Error using plot Invalid first data argument

조회 수: 2 (최근 30일)
Grace Hillman
Grace Hillman 2017년 11월 29일
댓글: Grace Hillman 2017년 11월 30일
I have an imported data set year:value1:value2 format. I assigned variables, year=C{1}; opioid_deaths=C{2}; heroin_deaths=C{3} This is my code for trying to create a plot - I keep getting the "error using plot; invalid first data argument"
% code
year=C{1};
plot(x,opioid_deaths,'b--+','LineWidth',2,x,heroin_deaths,'r:*','LineWidth',2)
title('Number of Opioid and Heroin Deaths in Maryland from 2007''FontSize',24,'FontName','Helvetica')
xlabel('Year','FontSize',18,'FontName','Helvetica')
ylabel('Number of deaths','FontSize',18,'FontName','Helvetica')
legend('Opioid deaths','Heroin deaths','Location','southwest','FontSize',18,'FontName','Helvetica')
hold on
% end
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 11월 29일
What is class(x) and class(opioid_deaths) ? And which MATLAB release are you using?
Grace Hillman
Grace Hillman 2017년 11월 29일
Class of opioid_deaths and heroin_deaths are both double. Sorry, I meant to replace x with the variable year (which is also class double).
I am using Matlab R2016A

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

답변 (1개)

Walter Roberson
Walter Roberson 2017년 11월 29일
I suspect that x is class datetime and that you are using a MATLAB version before R2016b; R2016b was the version that introduced using datetime for the x axis.
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 11월 30일
All name/value pairs must go at the end of the list, and you can only set linewidth for everything at once, not individually.
plot(x, opioid_deaths, 'b--+', x, heroin_deaths, 'r:*', 'LineWidth', 2)
Grace Hillman
Grace Hillman 2017년 11월 30일
This worked, thanks so much!

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by