I need some help with plotting a scatter plot in a for loop
古いコメントを表示
I am given z = (sin(xy))^2, x and y. z is used for to represent color coding. I need to create a 2-D x-y scatter plot of z = (sin(xy))^2. I am required to plot each point using the for loop. I can get it to plot x(i), y(i) no problem. That creates a linear relationship.
The graph I am trying to make does x(1),y(1) x(1),y(2) up to x(1),y(end) and the same idea for y: x(1),y(1) x(2),y(1) up to x(end),y(1). That way it populates the entire plane and creates a color pattern. I'm not sure how to do that.
if true
x = -3:0.1:3;
y = -3:0.1:3;
z = (sin(x.*y)).^2;
hold on
for i = 1:length(x)
if z(i) < 0.1
plot(x(z),y(z),'sb')
elseif z(i) > 0.1 && z(i) < 0.5
plot(x(i),y(i),'sc')
elseif z(i) > 0.5 && z(i) < 0.75
plot(x(i),y(i),'sg')
elseif z(i) > 0.75 && z(i) < 0.95
plot(x(i),y(i),'sr')
else
plot(x(i),y(i),'sk')
end
xlim([-3 3])
ylim([-3 3])
end
hold off
end
1 件のコメント
per isakson
2016 年 2 月 17 日
編集済み: per isakson
2016 年 2 月 17 日
Replace
plot(x(z),y(z),'sb')
by
plot(x(i),y(i),'sb')
to make the script run. However, the result is not what you want.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



