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

14 vues (au cours des 30 derniers jours)
Kevin Steerman
Kevin Steerman le 16 Fév 2016
Commenté : KSSV le 16 Fév 2016
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

Réponse acceptée

KSSV
KSSV le 16 Fév 2016
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 commentaires
Kevin Steerman
Kevin Steerman le 16 Fév 2016
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 le 16 Fév 2016
'S' must be a string; which specifies marker and color.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by