Error: "Invalid first data argument" (when attempting to plot)
19 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
KSSV
on 16 Feb 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 Comments
More Answers (0)
See Also
Categories
Find more on Filter Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!