fid,fopen,fscanf, help
19 views (last 30 days)
Show older comments
Question reads as follows: Using fopen() function read the data from “Data_excel_2.txt” , the file has 4 columns. Then plot three lines in one graph, (i) col #1 vs. Col#2, (ii) col #1 vs. Col#3, (iii) col #1 vs. Col#4.
fid=fopen('Data_excel_2.txt','r');
data=fscanf(fid,'%f %f %f %f',[4,inf])';
fclose(fid);
plot(data(:,4),data(:,4));
...that's as far as I got. I keep getting an error with the plotting so I wouldn't know how to set that up. I'm new to Matlab, so any help is much appreciated. Thank you!
-Stephanie
0 Comments
Answers (1)
KSSV
on 16 Nov 2017
Edited: KSSV
on 16 Nov 2017
fid = fopen('Data_excel_2.txt','r');
data=fscanf(fid,'%f %f %f %f',[4,inf]);
fclose(fid);
figure
plot(data(:,1),data(:,2:4))
2 Comments
KSSV
on 16 Nov 2017
This is working very fine for me....else you use
data=importdata('Data_excel_2.txt);
figure
plot(data(:,1),data(:,2:4))
When you use importdata I am assuming that there are no text data in the file. Also there was a transpose in the above, code..that is removed..you check again.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!