Info

この質問は閉じられています。 編集または回答するには再度開いてください。

colourful image labeling by using plot function to generate a scatter plot

1 回表示 (過去 30 日間)
Niki
Niki 2014 年 10 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have two vectors with 1000 length each. for example
r1 = rand(1000,1);
r2 = rand(1000,1);
then I want to plot a scatter which shows r1 versus r2 as follows:
plot(r1, r2, 'or')
I want to show each two values of r1 and 2 with the same color but different from the rest. any suggestion ?
I wrote something but it does not fully help me
for i=1:size(r1,1)
plot(r1 (i,1),r2 (i,2),'o')
hold all
end

回答 (2 件)

Mike Garrity
Mike Garrity 2014 年 10 月 10 日
The scatter command lets you assign a color to each marker using the CData property:
h = scatter(r1,r2,'or')
set(h,'CData',1:1000)
Is that what you're looking for?
  1 件のコメント
Niki
Niki 2014 年 10 月 10 日
Not really, as I explained above, I want to plot for example the first two values in blue, then then second two values in green etc. In general, each two of those scatter will have the same color.

Mike Garrity
Mike Garrity 2014 年 10 月 10 日
I'm not quite sure I follow, but if your CData array looks like:
[1, 1, 2, 2, 3, 3, ...]
then every pair of markers will be the same color.
For example:
c = 1:500; % go through colormap in order
c = repmat(c,2,1);
set(h,'CData',c(:));
or
c = randi(64,1,500); % 64 random colors
c = repmat(c,2,1);
set(h,'CData',c(:));

Community Treasure Hunt

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

Start Hunting!

Translated by