Want to create colors depending on the number of columns i got in my X

Hello, i want to plot each column, and i want to associate each column with a color but automaticly.
X = [1:26]';
Y = [1:26]';
[n,m] = size(X);
rows = 3;
columns = ceil(n/rows);
extra_row = columns * rows;
X(n+1:extra_row) = NaN;
X_new = reshape(X,rows,columns)
So, if i put a different numbe ron "ROWS" my "X_NEW" will have more or less columns.
Question -> How to create a vector of colors or string of colors depending on the number of columns of X_new?
Thanks for your time

 채택된 답변

Jan
Jan 2018년 11월 26일
What about:
CMap = parula(rows)

댓글 수: 5

Sorry, i made a loop for and i plot each j and solved my problem like that has maltab selects the colors he wants, tought i canceled this question since i found how to do it.
colormap winter % for example
for k = 1:10
plot(X(:,k),Y(:,k),'*')
hold on
end
This will give me 10 plots, each one with a different color, but the plot 8 or 9, it repeats the color from plot1, how can I change this with the color maps?
Jan
Jan 2018년 11월 27일
편집: Jan 2018년 11월 27일
As I have suggested already:
CMap = winter(10);
for k = 1:10
plot(1:10, rand(1,10), '*', 'Color', CMap(k, :));
hold on
end
legend
There is no large difference in the 10 different colors of the winter color map, but at least the colors are not repeated.
oh ok. I place with a vector
plot(1:10, rand(1,10), '*', 'Color', [CMap(k,1) CMap(k,2) CMap(k,3)]);
thanks!
Jan
Jan 2018년 11월 27일
편집: Jan 2018년 11월 27일
CMap(k, :) is the abbreviation for CMap(k, 1:3), which is exactly the same as [CMap(k,1) CMap(k,2) CMap(k,3)], so I'd prefer the leaner notation.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기

태그

질문:

2018년 11월 26일

편집:

Jan
2018년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by