Azzera filtri
Azzera filtri

MATLAB won't plot my graph

3 visualizzazioni (ultimi 30 giorni)
Ian Connelly
Ian Connelly il 25 Feb 2016
Modificato: Jason Allnutt il 25 Feb 2016
So I'm trying to get the following code to plot on a graph:
for x = -3.0:0.1:3.0
for y = -3.0:0.1:3.0
for z = power((sin(x.*y)),2)
figure
if (z < 0.1)
plot(x,y, 's', 'b')
hold
elseif (z >= 0.1 && z < 0.5)
plot(x,y, 's', 'c')
hold
elseif (z >= 0.5 && z < 0.75)
plot(x,y, 's', 'g')
hold
elseif (z >= 0.75 && z < 0.95)
plot(x,y, 's', 'r')
hold
else
plot(x,y, 's', 'k')
hold
end
end
end
end
And it keeps throwing "Error using plot Invalid first data argument" at me I'm not quite sure why, considering in the first iteration of the loop, x and y are only defined as one number, not a vector.
Any help would be appreciated.

Risposte (2)

Walter Roberson
Walter Roberson il 25 Feb 2016
When you use two quoted strings like that, plot (at least in R2014a) tries to interpret the 's' as being the name of a property. If you are trying to use 's' as the marker shape and then a separate color, then you need to either combine the two into a single linespec like 'sb' or else you need to switch over to using a name/value pair like 's', 'color', 'b' or the fuller 'marker', 's', 'color', 'b'

Jason Allnutt
Jason Allnutt il 25 Feb 2016
Modificato: Jason Allnutt il 25 Feb 2016
Also, you're "figure" command and the individual "hold" commands gave me trouble when I tested your code. In the sample I have provided I removed the "figure" call and moved a single "hold on" command to the beginning of the script.
Not sure if the outcome is what you expected but please run it and let me know.
hold on
for x = -3.0:0.1:3.0
for y = -3.0:0.1:3.0
for z = power((sin(x.*y)),2)
if (z < 0.1)
plot(x,y, 'sb')
elseif (z >= 0.1 && z < 0.5)
plot(x,y, 'sc')
elseif (z >= 0.5 && z < 0.75)
plot(x,y, 'sg')
elseif (z >= 0.75 && z < 0.95)
plot(x,y, 'sr')
else
plot(x,y, 'sk')
end
end
end
end

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by