How to make a 2D graph from text file

조회 수: 4 (최근 30일)
Dennis Wikan
Dennis Wikan 2017년 4월 4일
편집: Joseph Cheng 2017년 4월 5일
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))

답변 (1개)

Joseph Cheng
Joseph Cheng 2017년 4월 5일
편집: Joseph Cheng 2017년 4월 5일
I can point out a few things.
  1. if you look at M isn't that what you're trying to plot with A? as it should include both columns of data.
  2. your fscanf starts off at with a row of t;p which it doesn't recognize.
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

카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by