- if you look at M isn't that what you're trying to plot with A? as it should include both columns of data.
- your fscanf starts off at with a row of t;p which it doesn't recognize.
How to make a 2D graph from text file
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want the x-axis to represent the time and the y-axis to represent pressure. This is what I am working with now: fid=fopen('1.sec.txt','rt') for i=1:2, fgetl(fid),end M = dlmread('1.sec.txt',';',4,0) A=fscanf(fid,'%f',[2,inf])'; fclose(fid) subplot(2,1,1) plot(A(:,1),A(:,2))
And this is the error message the program gives me: Index exceeds matrix dimensions.
Error in txtfiltest (line 7) plot(A(:,1),A(:,2))
0 commentaires
Réponses (1)
Joseph Cheng
le 5 Avr 2017
Modifié(e) : Joseph Cheng
le 5 Avr 2017
I can point out a few things.
fid=fopen('test.txt','rt')
for i=1:4, fgetl(fid),end
M = dlmread('test.txt',';',4,0)
A=fscanf(fid,'%f;%f',[2,inf])';
fclose(fid)
subplot(2,1,1),plot(A(:,1),A(:,2))
the above code is rigged with a test case i ran of a similar file like your picture. so instead of just 2 fgetl's i do 4 to get the position in the file to the starting point of the data. Also I put the ';%f' in there as i do not think it recognizes ';' as a deliminator. I cannot find the documentation but from the examples of fscanf i think it is looking for a \tab. Hopefully someone comes along and corrects me on that
0 commentaires
Voir également
Catégories
En savoir plus sur Directed Graphs dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!