Error: "Invalid first data argument" (when attempting to plot)
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kevin Steerman
el 16 de Feb. de 2016
Comentada: KSSV
el 16 de Feb. de 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
0 comentarios
Respuesta aceptada
KSSV
el 16 de Feb. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Filter Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!