×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

Importing data

Importing data

Importing data

(OP)
hi there! Thanks for this great forum and all you valuable contributors too! lovely job.

I am very very new to MATlab and only really need it to do some graphs for me which excel is unable to cope with (ie. too large data points for a worksheet)

My data is usuaally stored in a notepad file. This .txt file consists of two columns for the X and Y data points. However the file has output from several experiments. let me show you what my text file contains .

*notepad file*

Main Title = one cyc fullsystem.wmd, Amplitude vs Frequency
X Title = Frequency (MHz)
Y Title = Amp.
Legend = T - Rx3.1
0 0.000101
0.00823049 0.000305
0.016461 0.000175
0.0246915 0.000244
0.032922 0.000278
0.0411525 0.000141
0.0493829 0.000122
0.0576134 0.000460
0.0658439 0.000674
.
.
.

Legend = T - Rx3.2
0 0.000316
0.00823049 0.000425
0.016461 0.000181
0.0246915 0.000285
0.032922 0.000248
0.0411525 0.000148
.
.
.
Legend = T - Rx3.3
0 0.000004
0.00823049 0.000174
0.016461 0.000282
0.0246915 0.000142
0.032922 0.000289
0.0411525 0.000108
0.0493829 0.000244
0.0576134 0.000312

and so on

Each data set has quite a lot of data points and so I can't do a copy paste into excel for this reason.

So I was wondering if someone could tell me if I could import this data into Matlab and get matlab to do the plotting for me. ie. can i export this data in the .txt file (with text in it) to Matlab so that it would plot a graph for me.

I've tried to find some help on this on the web and books but have had no luck.
I would very much appreciate some help on this PLEASE PLEASE    

RE: Importing data

1. i dont understand what the legend part of the file contains.
in principal you can do file open and open your file in matlab

RE: Importing data

(OP)
thanks for the reply yairsuari. Once I open the file via this method how would I use the data to plot a graph? this text file contains text in between. How can I play around with the data points and make graphs?

Thanks

RE: Importing data

You need to use the low level I/O functions like "fscanf". Read in one line at a time and check to see if it is header information or numerical data. If each experiment data set in a file has the same  number of data points then you can read them in chunks to speed things up.

M

--
Dr Michael F Platten

RE: Importing data

(OP)
Hi Mikey-thanks for that. Was wondering if you knew what kind of code I'd have to write cos all the files will have the same number of data. I am no where close to a programmer so could you possibly PLEASE give me a kick start?
Thanks in advance

RE: Importing data

look at the help for "fopen", "fclose" and "fscanf". It might help also to look at an ANSI C manual as the fscanf function is pretty much the same in C and is not very well explained in the Matlab online help. Try it with some simple text files that you have generated by hand to see how it works.

M

--
Dr Michael F Platten

RE: Importing data

Maybe something like ?

fid = fopen('yourfile.txt','r');

%skip first 3 lines
for i=1:3
 line = fscanf(fid,'%s\n');
end

n = number of data per set;
p = number of set;
for j=1:p
 for i=1:n
  line = fscanf(fid,'%s\n');
  my_data(i,j)=str2num(line);
 end
 line = fscanf(fid,'%s\n');
 legend{j} = line;
end

fclose(fid);

Good luck,

FF

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!


Resources