Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing data 1

Status
Not open for further replies.

doop4

Electrical
May 23, 2006
15
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
 
Replies continue below

Recommended for you

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
 
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
 
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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor