필터 지우기
필터 지우기

How to plot data in block?

조회 수: 4 (최근 30일)
hit8hot
hit8hot 2015년 10월 1일
댓글: hit8hot 2015년 10월 6일
Hello, I've data in .txt file as follows:
-42.135 -40.263 -38.384 -36.498 -34.608 -32.712 -30.811 -28.907 -26.999 -25.088
-23.174 -21.258 -19.339 -17.419 -15.497 -13.573 -11.648 -9.723 -7.796 -5.868
-3.940 -2.012 -0.084 1.845 3.773 5.701 7.629 9.555 11.481 13.406
15.330 17.252 19.173 21.092 23.008 24.922 26.833 28.742 30.646 32.547
34.443 36.335 38.220 40.100 41.972 43.837 45.692 47.537 49.371 51.191
52.995 54.781
5.543 5.325 5.061 4.786 4.535 4.328 4.146 3.988 3.864 3.779
3.728 3.705 3.715 3.763 3.862 4.044 4.375 4.985 6.032 7.594
9.759 12.214 13.494 14.008 13.810 13.130 12.751 12.998 13.764 14.557
14.307 13.415 13.135 13.130 12.965 12.590 11.975 11.391 10.867 10.446
10.088 9.760 9.401 9.021 8.594 8.124 7.615 7.106 6.737 6.495
6.292 6.119
I want to plot above upper block(52 data points) data in x-axis and that in lower block in y-axis using matlab command. Any suggestions?

채택된 답변

dpb
dpb 2015년 10월 1일
Knowing the length of the data sections makes it pretty easy even though they're not regular in the file--
fid=fopen('yourfile.txt','r'); % open the data file to read...
x=fscanf(fid,'%f',52); % read the known number of x values
y=fscanf(fid,'%f',52); % followed by y values
fid=fclose(fid);
plot(x,y)
NB: that fscanf will
  1. Read the first N requested values (and no more) into 'x', and then
  2. skip the blanks in the file to read the 52 more values into 'y'
Since that works like magic, afterwards the plotting is trivial. If use importdata or one of the other higher-level routines, it would read all the data but then you've got a mess in trying to sort out "who's who in the zoo" as those routines will return a regular array w/ NaN for the missing values in the rows shorter than the rest.
  댓글 수: 1
hit8hot
hit8hot 2015년 10월 6일
Thank you. It really works!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Kirby Fears
Kirby Fears 2015년 10월 1일
Get the data into your Matlab workspace using the import data tool or one of the following functions: importdata,dlmread,textscan.
You should be able to split the data into two matrices X and Y easily. Afterward you can vectorize X and Y then plot.
X = X(:); % vectorizing X
Y = Y(:); % vectorizing Y
plot(X,Y);
Hope this helps.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by