Error: "Invalid first data argument" (when attempting to plot)

조회 수: 19 (최근 30일)
Kevin Steerman
Kevin Steerman 2016년 2월 16일
댓글: KSSV 2016년 2월 16일
I am trying to create a scatter plot of: z = ( sin(xy) )2 , where x and y are both independent variables and each point is shown as a square with a defined color (based on it's value). Whenever I attempt to run the code I get the "Invalid first argument" error and it directs me to line 14: (plot(x,y,'s','c')). I honestly have no idea what this means. I have been using MATLAB for only a few months now so practically everything is still pretty new to me. Also, I am supposed to use a for loop to plot each point one-by-one.
if true
x = -3:0.1:3;
y = -3:0.1:3;
z = (sin(x.*y)).^2;
for i = 1:length(z)
if z(i) < 0.1
plot(x,y,'s','b');
elseif z(i) > 0.1 && z(i) < 0.5
plot(x,y,'s','c')
elseif z(i) > 0.5 && z(i) < 0.75
plot(x,y,'s','g')
elseif z(i) > 0.75 && z(i) < 0.95
plot(x,y,'s','r')
else
plot(x,y,'s','b')
end
end
end

채택된 답변

KSSV
KSSV 2016년 2월 16일
Hello what is 's' in the plot command? 's' has no meaning in plot. You have to follow as below.
if true
x = -3:0.1:3;
y = -3:0.1:3;
z = (sin(x.*y)).^2;
for i = 1:length(z)
if z(i) < 0.1
plot(x,y,'.b');
elseif z(i) > 0.1 && z(i) < 0.5
plot(x,y,'.c')
elseif z(i) > 0.5 && z(i) < 0.75
plot(x,y,'.g')
elseif z(i) > 0.75 && z(i) < 0.95
plot(x,y,'.r')
else
plot(x,y,'.b')
end
end
end
  댓글 수: 2
Kevin Steerman
Kevin Steerman 2016년 2월 16일
When I used the "help plot" function, it said that 'S' would creat square data points. And by looking at the edited code you posted, since my x and y values are multi-column vectors, by using the 'b' (as I did) it was trying to do the integer procedure because I did not specify my x and y datas are vectors. Is that statement correct?
Also, thank you so much for your response!
KSSV
KSSV 2016년 2월 16일
'S' must be a string; which specifies marker and color.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by