Thread Subject: plot command changing style and color in for loop

Subject: plot command changing style and color in for loop

From: Frankele ele

Date: 25 Oct, 2009 11:36:01

Message: 1 of 2

Hey there,

i'm currently wrting on a few matlab files to evaluate the shape of a hystersis loop.
So i got 3 m-files. (input, calculation/simulation, plot)

What I want to do: I got a formula depending on 7 parameters. And I want to give out a plot which shows me the change of the hystersis loop when changing one parameter. Therefore i created a for loop which is simulating my simulink model 3 times. Everytime the simulink model picks the changed parameter out of the vector i created.

e.g.
betav=[1, 2, 3]
beta=betav(i)
this way my parameter beta is changed in the simulation
after the simulation, the programm does some calculations with the data comin from the simulation.

now I want to plot that stuff
so I created a vector
color=['b','g','r']
then there is my for loop for the plot

for i=1:3
plot(datax(i,:), datay(i,:), color(i));
end

this works fine
but when i want to have something like this
color=[':b',':g',':r']
matlab ignores my input in the color vector and simply prints it in blue lines
what can I do?
I already tried something like
set(gca,'LineStyleOrder',{'-*','-o','-v','-p','-^','-d'});
but then i get no plot at all :/

regards Frank

Subject: plot command changing style and color in for loop

From: Phil Goddard

Date: 25 Oct, 2009 18:34:01

Message: 2 of 2


color=[':b',':g',':r'];
is equivalent to creating the 6 element vector
color =':b:g:r';

Hence
for i=1:3
   plot(datax(i,:), datay(i,:), color(i));
end
will give you lines using ':', 'b' and then ':', all of which will be blue.

There are multiple ways of doing what you want, one would be to use cell arrays

color = {':b',':g',':r'};
for i=1:3
   plot(datax(i,:), datay(i,:), color{i});
end

(Note the curly braces.)

Phil.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
plot Frankele ele 25 Oct, 2009 07:39:03
linestyle Frankele ele 25 Oct, 2009 07:39:03
for loop Frankele ele 25 Oct, 2009 07:39:03
rssFeed for this Thread

Contact us at files@mathworks.com