fid,fopen,fscanf, help

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

Answers (1)

KSSV
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

Hi, thank you for the response. I keep getting an error:
"Index exceeds matrix dimensions."
-Thanks
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.

Sign in to comment.

Categories

Tags

Asked:

on 16 Nov 2017

Commented:

on 16 Nov 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!