필터 지우기
필터 지우기

MATLAB won't plot my graph

조회 수: 3 (최근 30일)
Ian Connelly
Ian Connelly 2016년 2월 25일
편집: Jason Allnutt 2016년 2월 25일
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.

답변 (2개)

Walter Roberson
Walter Roberson 2016년 2월 25일
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 2016년 2월 25일
편집: Jason Allnutt 2016년 2월 25일
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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by