-2

Following this, i've plotted a matrix of signals t (m by 1) and x (m by n):

 plot(t,x);

and, after that, i am wishing to apply a coloured scheme on colormap matrix c (n by 3). How to do it?

EDIT Trivially, and ignoring most -if not all- performance etiquette, through a for call you can set colours while building a plot, plotting each column inside the loop, and setting/applying the colormap 'on the fly', just as suggested by the pointed post, but which is not the question:

for i=1:n
    plot(t(:,1),x(:,i),'Color',c(i,:));
    hold on;
end

This is pseudocode which will not run if you don't have t, x and c defined. Data, and the code shown here, cooked, just ready for you:

load spectra.mat; 
x=NIR'; m=size(x,1);n=size(x,2);
t=900+2*(1:m)'; %Don't question this :)...
c=winter(n);
for i=1:n
    plot(t(:,1),x(:,i),'Color',c(i,:));
    hold on;
end
title('Near Infrarred Spectra for Gasoline Samples');
xlabel('Wavelength [nm]');
ylabel('Infrarred Spectral Magnitude [lm^2/nm]');

or without the for, better:

load spectra.mat; 
x=NIR'; m=size(x,1);n=size(x,2);
t=900+2*(1:m)'; %Don't question this :)...
c=winter(n);
set(0,'DefaultAxesColorOrder',c);
plot(t,x);
title('Near Infrarred Spectra for Gasoline Samples');
xlabel('Wavelength [nm]');
ylabel('Infrarred Spectral Magnitude [lm^2/nm]');

Spectral example.

All them unfortunately prior the plotting. Never after...

Community
  • 1
  • 1
Brethlosze
  • 1,533
  • 1
  • 22
  • 41
  • The problem is explained. I am truly, positive clear that no data nor further code is required, if you are used to MATLAB. If there were a trivial solution i wouldnt be asking. – Brethlosze May 23 '15 at 07:04
  • What do you mean by "All them unfurtunately prior the plotting. Never after..." ? I have tried both versions of your code with a dummy `NIR` and it works just fine. – Tamás Szabó May 24 '15 at 09:46
  • The code works fine, but the OP wants to first plot the lines, _then_ change their colors. I think this would require iterating over the Lineseries objects one by one. – buzjwa May 24 '15 at 18:04
  • @Tamás. The question is to change colours of plotted lines. Already plotted lines. Plot could come from a plotting function, or existing | compiled code. Or from existing FIG files. Whatever, after the `plot` command was already commited. @Naveh. Lineseries iteration could be the only solution i see AFAIK too. Maybe there is a solution in the MExchange site. – Brethlosze May 25 '15 at 12:21

1 Answers1

0

I've found this function (CMAPLINE):

plot(t,x,':o');
cmapline('colormap',c);

Which solves the issue. Thanks for the comments, buddies.

hypfco.

Brethlosze
  • 1,533
  • 1
  • 22
  • 41