Problem "Invalid first data argument" when plot a figure

조회 수: 6 (최근 30일)
Ha Le Thanh
Ha Le Thanh 2017년 12월 25일
편집: ANKUR KUMAR 2017년 12월 26일
Dear Colleagues My name is Le Thanh Ha. I am quite new to Matlab. I write a code to draw a figure, but the problem came out like "Invalid first data argument" and I do not know to what is the problem and how to figure out it. Please give me some advice to overcome it. Any comment and suggestion is greatly appreciated. Best

채택된 답변

ANKUR KUMAR
ANKUR KUMAR 2017년 12월 25일
hold on
x=(1:127);
col={'b','r','k','y'}
data={vxo_cycle*0.1,gdp_cycle*0.01,pi_cycle,hoursworked_cycle}
for ii=1:4
plot(x,data{ii},col{ii})
hold on
end
  댓글 수: 2
Ha Le Thanh
Ha Le Thanh 2017년 12월 26일
Thank you so much for your help Regarding your revised code, please let me know how to legend lines as I described in my code. I make some changes but it is weird when matlab legend them thank you so much Best
ANKUR KUMAR
ANKUR KUMAR 2017년 12월 26일
편집: ANKUR KUMAR 2017년 12월 26일
for legends
Just type legends once the loop ends
For example
A={randi(25,1,121),randi(25,1,121),randi(25,1,121),randi(25,1,121)} %You can write only one time. As it changes after execution
x=(1:121);
col={'r','b','k','g'}
for i=1:4
plot(x,A{i},col{i})
hold on
end
legend('First Data','Second Data','ThirdData','Fourth Data')

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 12월 26일
ppp=plot(1:127,vxo_cycle*0.1,'b',1:127,gdp_cycle*0.01,'r',1:127,pi_cycle,'k','LineWidth',hoursworked_cycle,'y','LineWidth',1.5);
has 'LineWidth' and then a variable. The 'LineWidth' is a named option and once you have started named options you cannot have any more positional parameters. However after that you then have 'y' which is not one of the named options: it is a positional line style option. But if there did happen to be a named option beginning with 'y' it would have to be followed by a value, which in this case would have to be that second 'LineWidth'. Then after that you have 1.5 which is not a valid option name.
Probably the first LineWidth should have been a variable name.

카테고리

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