From: saraceno on
Hi to all
I have trivial yet puzzling problem
I want to plot a function for different values of a parameter. So far
so good:
clear;
clf;
g=5;
s=[];
for ps=1:2:9
s=[s; sprintf('%s%g','\psi=',ps)];
fplot(@(gc) g^2/(gc/ps+g),[0,40]);
hold on
end
legend(s);
This correctly does it, and creates a legend with the different values
of psi.
My problem is that they are all blue.
I'd like to change the colors and/or the line style (the latter being
preferred for b/w printing). How can I do it? I tried various things,
but they did not work. Fro example, I tried
col=1
lines=strvcat(':k','-.r','-c',':y','--m');
s=[];
for ps=1:2:9
s=[s; sprintf('%s%g','\psi=',ps)];
fplot(@(gc) g^2/(gc/ps+g),[0,40], lines(col));
hold on
col=col+1;
psi=[psi;ps];
end
legend(s);
and I obtained some solid, some dotted blue lines. And I am unable to
undestand what I did wrong...
Any help would be appreciated!!

thanks
francesco

From: ImageAnalyst on
Can't you just get a random color (using rand()) and then pass that in
as the 'Color' option to the plot() function?
From: TideMan on
On Apr 8, 10:16 am, saraceno <sarac...(a)gmail.com> wrote:
> Hi to all
> I have trivial yet puzzling problem
> I want to plot a function for different values of a parameter. So far
> so good:
> clear;
> clf;
> g=5;
> s=[];
> for ps=1:2:9
>     s=[s; sprintf('%s%g','\psi=',ps)];
>     fplot(@(gc) g^2/(gc/ps+g),[0,40]);
>     hold on
> end
> legend(s);
> This correctly does it, and creates a legend with the different values
> of psi.
> My problem is that they are all blue.
> I'd like to change the colors and/or the line style (the latter being
> preferred for b/w printing). How can I do it? I tried various things,
> but they did not work. Fro example, I tried
> col=1
> lines=strvcat(':k','-.r','-c',':y','--m');
> s=[];
> for ps=1:2:9
>     s=[s; sprintf('%s%g','\psi=',ps)];
>     fplot(@(gc) g^2/(gc/ps+g),[0,40], lines(col));
>     hold on
>     col=col+1;
>     psi=[psi;ps];
> end
> legend(s);
> and I obtained some solid, some dotted blue lines.  And I am unable to
> undestand what I did wrong...
> Any help would be appreciated!!
>
> thanks
> francesco

Instead of:
lines=strvcat(':k','-.r','-c',':y','--m');
use:
lines={':k','-.r','-c',':y','--m'}; % Notice the curly brackets
Then in your plot command use lines{col}, not lines(col).
From: Matt Fig on
I didn't look over your code for errors, but when I do something like this I use a cell:


>> STR = {':k','-.r','-c',':y','--m'};
>> axes; hold on, for ii = 1:5,plot((0:.1:1),(0:.1:1).^ii,STR{ii});end