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

19 次查看(过去 30 天)
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!

请先登录,再进行评论。

更多回答(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