×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

importing a text file into a vector

importing a text file into a vector

importing a text file into a vector

(OP)
I have a text file and i would like to read its content into a vector x in my m file, i looked at help section in Matlab and tried many function but it still doesnt work, does anyone know how to do it .. e.g

content of my text file is and its in the directory C:\work\work.txt

A former senior Partner whose association with the firm dates back to 1958, John "retired" in 1995 only to come back as the firm's Specialist Consultant in Clinical Negligence. A member of the Law Society Clinical Negligence panel, John has a formidable reputation both locally and regionally.

Educated at Gordonstoun and Liverpool University, John qualified as a solicitor in 1958 after "articles" in a practice on Merseyside.



i tried to command in my m file as

[x] = textread('C:\work\work.txt ','%c')

i am not quite sure which format i should use, but all the content in my text file are ASCII character ...

RE: importing a text file into a vector

Try using importdata, such as:

x=importdata('hey.txt');

If the file hey.txt contains the text: "Hey, how are u",

Matlab will display in the command window (upon entering 'x'):

'Hey, how are u'

RE: importing a text file into a vector

(OP)
Thanks very much to P4t for the replied ... i know the command

x=importdata('hey.txt');

can display the content of hey.txt on the command window.. but i want the number of characters inside the file hey.txt store into the variable x so that i can use the variable x to do some other task, do u know how to do it ??

RE: importing a text file into a vector

I would start by opening the text file, then reading in the text as a large text string.  You can then manipulate the string to find what you want.

fid = fopen('C:\work\work.txt ');
b=fscanf(fid,'%c')
c = length(b)
fclose(fid)

This one just finds the length of the string (including whitespace characters).

The trouble with textread is that it automatically assumes you want to ignore whitespace, or use whitespace as delimiters.

Don't know what you want to do with the string, but this should at least get it into matlab to manipulate it.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now