Plot blocks of points with a specific color
古いコメントを表示
Hi,
I got these points and I want to colour every 4 points with a specific color:
x = [ 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5]';
y = [ 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]';
Point 1:4 yellow, 5:8 blue, 9:12 red, etc, and I want to plot all the 25 entries. the last "block" with just have the row number 25.
I though doing this:
[n,~] = size(x);
block_points = 4;
t_start = 1:block_points:n;
t_end = block_points:block_points:n;
but I got a problem with t_end, only has size 6, while t_start has size 7, due to the last block that only has 1 number.
Thanks for your help
4 件のコメント
madhan ravi
2018 年 11 月 28 日
If you keep closing the question it'll decrease your chance of getting an answer in the future
Tiago Dias
2018 年 11 月 28 日
madhan ravi
2018 年 11 月 28 日
編集済み: madhan ravi
2018 年 11 月 28 日
ok so the effort put in order to help is for nothing? Just leave it open just don‘t accept the answer. Post your solution as an answer and accept it.
Tiago Dias
2018 年 11 月 28 日
採用された回答
その他の回答 (1 件)
madhan ravi
2018 年 11 月 26 日
編集済み: madhan ravi
2018 年 11 月 26 日
EDITED
xx = [ 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5]';
yy = [ 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]';
x=reshape(xx(1:end-1),4,[]);
y=reshape(yy(1:end-1),4,[]);
s={'-oy','-ob','-or','-og','-om','-oy'};
for i=1:size(x,1)
plot(x(i,:),y(i,:),s{i})
hold on
end
plot(xx(end),yy(end),'ok',...
'markerFaceColor','k')
9 件のコメント
Tiago Dias
2018 年 11 月 26 日
編集済み: Tiago Dias
2018 年 11 月 26 日
madhan ravi
2018 年 11 月 26 日
yes in the similar way, read more about reshape()
Tiago Dias
2018 年 11 月 26 日
madhan ravi
2018 年 11 月 26 日
編集済み: madhan ravi
2018 年 11 月 26 日
yes because reshape splits a vector into the number of elements it has
Tiago Dias
2018 年 11 月 26 日
madhan ravi
2018 年 11 月 26 日
25th element is plotted after the loop , didn't you check my edited answer?
Tiago Dias
2018 年 11 月 26 日
編集済み: Tiago Dias
2018 年 11 月 26 日
madhan ravi
2018 年 11 月 26 日
編集済み: madhan ravi
2018 年 11 月 26 日
"I would transform a 26x1 matrix into a 4x7 matrix, with the 2 last entries could be NaN values for example."
matrix=[rand(26,1);zeros(2,1)] %this will do what you want just pad the remaining elements with zeros
Tiago Dias
2018 年 11 月 26 日
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!