get 2 set of random coordinates
2 ビュー (過去 30 日間)
古いコメントを表示
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/201382/image.png)
How to plot as above randomly with two colors
I have now given
xy = [2.5 4.5;
3.5 4.5;
4.5 4.5;
4.5 2.5;
3.5 3.5];
and plotted
what should i do to get 2 set of random coordinates and plot as shown in image attached. All locations should have a plot
2 件のコメント
Adam Danz
2019 年 1 月 24 日
Your title seems like you want to choose 2 colors randomly but the last sentence seems like you want to produce random coordinates. Can you explain the problems again?
採用された回答
Adam Danz
2019 年 1 月 24 日
編集済み: Adam Danz
2019 年 1 月 24 日
In this demo, I create a grid of coordinates identical to the plot in your question. Then I randomly select a subsection of them. Then I plot that subsection in red and the remaining coordinates in black.
%Produce coordinates
[x, y] = meshgrid( [1.5:1:5], [1.5:1:5]);
% randomly select a subset of coordinates
idx = logical(randi([0 1], size(x)));
% plot each subset
figure
plot(x(idx), y(idx), 'ro', 'markersize', 15, 'linewidth', 2);
hold on
plot(x(~idx), y(~idx), 'ko', 'markersize', 15, 'linewidth', 2);
xlim([1, 5])
ylim([1, 5])
% add grid
set(gca, 'xtick', 1:5)
set(gca, 'ytick', 1:5)
grid on
The figure produce is below (each reproduction will randomly select a different subset).
![190124 095159-Figure 1.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/201391/190124%20095159-Figure%201.jpeg)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!