[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: setting 'color' for a plot with multiple lines
From: |
Ben Abbott |
Subject: |
Re: setting 'color' for a plot with multiple lines |
Date: |
Sun, 20 Jan 2013 16:35:49 -0500 |
On Jan 20, 2013, at 3:58 PM, address@hidden wrote:
> Dear all,
>
> I want to set the colors to some standard without cycling through each of
> them manually or via a for-loop.
>
> The following script show my attempt and I do not understand why the last one
> doesn't work.
> (some plot() commands are commented to not let Octave stop at it).
>
> Can someone explain why the bottom plot() command doesn't work when I feed it
> a proper cell?
>
> --------------------------------------------------
>
> x=[linspace(0,2,30)' , linspace(0,2,30)'];
> y=x;
> y(:,1)=sin(x(:,1));
> y(:,2)=cos(x(:,2));
>
> figure
> p=plot(x,y);
> standardcolors=get(p,'color')
> % this works, but the colors are not what I want
>
> figure
> K=rainbow(size(y)(2));
> %p=plot(x,y,'color',K);
> %% this doesn't work. Because K is a matrix?
>
>
>
> figure
> KK=mat2cell(K,ones(1,size(K)(1)),3)
> whos standardcolors KK
>
> %plot(x,y,'color',KK)
> % why doesn't this work?
>
> figure
> p=plot(x,y)
> get(p,'color')
> set(p,'color',KK)
>
> --------------------------------------------------
>
> many thanks,
>
> indium
The syntax you're attempting is not valid. The set() command isn't specific to
a particular object type. Thus, properties can have values that belong to any
class ... including cells.
You can get the result you want with the line below.
arrayfun (@(n) set (p(n), 'color', KK{n}), 1:numel(p));
Ben