How to plot data with unlimited number of colours

  • Follow


Hi!

I'm implementing an algorithm with Matlab and I need to plot different points with different colors depending on which class each point belongs to. Here is the code I'm using:

    for i=1:fil
      x = data(i,:);
      y = w*x';

      c=strcmp(labels(i,1), classes(1,1));
      if (c)
         plot(y(1),y(2),'g.');
      end
      c=strcmp(labels(i,1), classes(2,1));
      if (c)
         plot(y(1),y(2),'r.');
      end
      c=strcmp(labels(i,1), classes(3,1));
      if (c)
         plot(y(1),y(2),'b.');
      end
      
      hold on
    end

With this, I compare the label of each point with a defined classes vector, and select one color for each class.
But I would like it to work with an undefined number of classes that I get reading a labels file and selecting the unique labels (classes) with unique().

How could I do this, because there are only a few colours available with plot function?

Thanks in andvance.
0
Reply asdf209 (154) 7/23/2007 12:51:15 PM

Dani:
<SNIP mistaken...

> ...because there are only a few colours available with plot
function...

no, <plot> takes any rgb color you want, eg

% some data
     ns=5;
     z=rand(10,ns);
     z=bsxfun(@plus,z,1:ns);
% some engines
% 1) one col/signal
     subplot(2,1,1);
     plot(z,'color',[.75,.5,.25]);
% 2) slightly more elaborate
     subplot(2,1,2);
     ph=plot(z);
     set(ph,{'color'},num2cell(jet(ns),2));

us
0
Reply us1 (8054) 7/23/2007 1:03:18 PM


Thank you very much.
You helped me a lot!
0
Reply asdf209 (154) 7/24/2007 11:18:08 AM

2 Replies
23 Views

(page loaded in 0.04 seconds)

Similiar Articles:













7/18/2012 11:55:04 AM


Reply: