필터 지우기
필터 지우기

Plot data from data file with unknown number of columns

조회 수: 2 (최근 30일)
prashant sharma
prashant sharma 2018년 10월 29일
댓글: KSSV 2018년 10월 29일
Hi to every one. I am a novice to MATLAB. I am trying to plot figures from a data file. The data file is generated using a software. The number of columns is not fixed and can be changed according to requirement. I want to build a script which can read the file and then plot it. Another thing is that I want to put header line as the legends of the plot. I am attaching the data file as well as the plot. Your kind help would be highly appreciated.***
Time Pop1 Pop2
1.0000000E-08 4.097568E-006 2.211371E-005
2.0000000E-08 3.511726E-006 1.775795E-005
3.0000000E-08 2.828558E-006 1.429533E-005
4.0000000E-08 2.265553E-006 1.154281E-005
5.0000000E-08 1.816197E-006 9.354735E-006
6.0000000E-08 1.458834E-006 7.615319E-006
7.0000000E-08 1.174745E-006 6.232541E-006
8.0000000E-08 9.489138E-007 5.133246E-006
9.0000000E-08 7.693916E-007 4.259290E-006
1.0000000E-07 6.266799E-007 3.564453E-006
Currently, I am using this script, but it is not generating legend with the plot.
clear all;
close all;
clc
A=dlmread('levelspp.dat','', 1, 0);
x=A(:,1);
B=dlmread('levelspd.dat','', 1, 0);
x1=B(:,1);
figure(2)
plot(x,A(:,2:end))
xlabel('Time (s)')
ylabel('Population')
figure(3)
plot(x1,B(:,2:end))
xlabel('Time (s)')
ylabel('Population')
  댓글 수: 2
madhan ravi
madhan ravi 2018년 10월 29일
upload your data file
prashant sharma
prashant sharma 2018년 10월 29일
Please find the attached files. Please change the file extension to .dat I am unable to upload .dat files. Thanks.

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

채택된 답변

KSSV
KSSV 2018년 10월 29일
편집: KSSV 2018년 10월 29일
YOu need not to know how many columns are present. You can use importdata to load the data.....and you can plot.
A = importdata('data.txt') ;
data = A.data ;
t = data(:,1) ; % time
y = data(:,2:end) ;
plot(t,y)
l = legend ;
l.String = strrep(l.String,'data','Pop')
If you want the number of columns. Use size. size(data) should give you the number of columns.
  댓글 수: 4
prashant sharma
prashant sharma 2018년 10월 29일
Thanks for your kind help.
KSSV
KSSV 2018년 10월 29일
Thanks is accepting and voting the answer.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by