필터 지우기
필터 지우기

get 2 set of random coordinates

조회 수: 2 (최근 30일)
Elysi Cochin
Elysi Cochin 2019년 1월 24일
편집: Adam Danz 2019년 1월 24일
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
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?
Elysi Cochin
Elysi Cochin 2019년 1월 24일
편집: Elysi Cochin 2019년 1월 24일
i want to select 2 set of random coordinates

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by