Asked by Tiago Dias
on 26 Nov 2018

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

Answer by Tiago Dias
on 28 Nov 2018

Accepted Answer

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

Sign in to comment.

Answer by madhan ravi
on 26 Nov 2018

Edited by madhan ravi
on 26 Nov 2018

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')

Tiago Dias
on 26 Nov 2018

I understood that, but if my X has 26 elements, i need to handly plot the last 2. if it has 27 i need to handly plot the last 3.

I would prefer, if it is doable, an aprroach that would read the size of X and reshape in function of the number 4, or 3 or 5 or whatever I need.

I would like to do a reshape of x, transform a X of 1xm into a 4xceil(n/4), where n is the number of rows of X.

I would transform a 26x1 matrix into a 4x7 matrix, with the 2 last entries could be NaN values for example.

x(1) x(5) x(9) x(13) x(17) x(21) x(25)

x(2) x(6) x(10) x(14) x(18) x(22) NaN

x(3) x(7) x(11) x(15) x(19) x(23) NaN

x(4) x(8) x(12) x(16) x(20) x(24) NaN

i want the reshape to do this, or someother tool to get this, when i say i need 4 rows and 7 columns, that i can calculate there 2 parameters based on my original x

madhan ravi
on 26 Nov 2018

"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
on 26 Nov 2018

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## madhan ravi (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/431963-plot-blocks-of-points-with-a-specific-color#comment_643393

## Tiago Dias (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/431963-plot-blocks-of-points-with-a-specific-color#comment_643395

## madhan ravi (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/431963-plot-blocks-of-points-with-a-specific-color#comment_643396

## Tiago Dias (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/431963-plot-blocks-of-points-with-a-specific-color#comment_643398

Sign in to comment.