how to plot multiple graphs on one figure
이전 댓글 표시
[EDIT: 20110531 13:53 CDT - reformat - WDR]
i have three curves in one figure
values are like this :
- x1 has the values from 10 to 30 and u have corresponding y1 values;
- x2 has the values 10 to 60 and u have corresponding y2 values;
- x3 has the values 10 to 90 and u have corresponding y3 values;
load myfig.txt
xdc1 = myfig(:,1);
ydc1 = myfig(:,2);
xdc2 = myfig(:,3);
ydc2 = myfig(:,4);
xdc3 = myfig(:,5);
ydc3 = myfig(:,6);
plot(xdc1,ydc1,xdc2,ydc2,xdc3,ydc3);
xlim([0 90]);
ylim([10 30]);
xlabel('Spark advance (degrees}');
ylabel('Power (kW)') ;
hleg1 = legend('dc = 30','dc = 60','dc = 90');
set(hleg1,'Location','SouthWest')
I AM GETTING THE FOLLOWING ERROR MESSAGE?
?? Error using ==> load
Number of columns on line 5 of ASCII file D:\ic\myfig.txt
must be the same as previous lines.
kindly tell me how to plot this graph
답변 (2개)
Walter Roberson
2011년 5월 31일
0 개 추천
Does your myfig.txt have some header lines?
The problem being reported is not with the plotting but right at the very beginning at the "load" statement. That kind of load() statement assumes that the input file just contains columns of numbers, the same number of columns on every line, and no text anywhere. If you have text anywhere, or if your columns are a fixed width (and might show up as blank to indicate 0 or missing data) then you need to read the data a different way.
The error message is telling you that line 5 of the file seems to have a different structure than lines 1-4.
댓글 수: 4
Vijaya
2011년 5월 31일
Vijaya
2011년 5월 31일
Walter Roberson
2011년 5월 31일
You cannot use load() to read in a file that has that structure.
Vijaya
2011년 5월 31일
Matt Fig
2011년 5월 31일
There is probably a better way to do this, but here is what I did. I made a text file that looks like this (as you describe):
3 5 6
4 6 7
5 8 9
6 7 8
7 8 9
10
11
14
15
16
17
12
13
14
15
18
19
Then I imported it like this:
fid = fopen('myfile.txt');
T = textscan(fid,'%d%d%d')
T{3}(6:size(T{1},1)) = T{1}(6:end);
T{1} = T{1}(1:5);
T{2} = T{2}(1:5);
fclose(fid)
Now T{1} has the first column, T{2} has the second column, and T{3} has the third column as from the text file.
댓글 수: 2
Vijaya
2011년 6월 1일
Walter Roberson
2011년 6월 1일
The values are tab separated? And is there a tab for every empty value? If so then textscan() with 'Delimiter', '\t' and 'EmptyValue',nan). You would not even need to remove the nan() before plotting.
카테고리
도움말 센터 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!