Plot blocks of points with a specific color

조회 수: 6 (최근 30일)
Tiago Dias
Tiago Dias 2018년 11월 26일
답변: Tiago Dias 2018년 11월 28일
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
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
Tiago Dias 2018년 11월 28일
First of all, I did not say that your help was for nothing, I appreatiate the time you spend on my question, like I wrote in the last comment I wrote.
I think I should not accept your answer since, it was not what I looking for, I wanted a more automatic procedure, depending on the variables and not the numbers. I was looking for something that could always work, no matter the X and Y provided, and I was able to acomplish that.
Like I said, thanks for your interest in my question, and the effort that you spent on it.

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

채택된 답변

Tiago Dias
Tiago Dias 2018년 11월 28일
This is what I did to solve my question:
from a generic
X = [1:25]';
Y = [1:25]';
I want to plot each number of "rows" to a specific color
[n,m] = size(X);
rows = 3;
columns = ceil(n/rows);
extra_row = columns * rows;
X(n+1:extra_row) = NaN; Y(n+1:extra_row) = NaN;
X_new = reshape(X,rows,columns); Y_new = reshape(Y,rows,columns);
legenda = sprintfc('Mes %d', 1:columns);
for j = 1:size(X_new,2)
plot(X_new(:,j),Y_new(:,j),'*')
hold on
end

추가 답변 (1개)

madhan ravi
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
madhan ravi
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
Tiago Dias 2018년 11월 26일
I am not explaining my self properly, i want it to be automaticly, i created a new topic for this, thanks for your time !

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by