Date: Jan 24, 2013 10:13 AM
Author: Steven Lord
Subject: Re: Passing arguments to plot command

"Nicolas " <> wrote in message
> Hello all,
> I am trying to pass some string arguments to the plot command. Below is a
> little script that I wrote.
> **********
> close all;
> clear all;
> x = 1:10;
> y = 2.*x;
> trace1 = '-sb'
> trace2 = [' ''linestyle'',''-'',''marker'',''s'',''color'',[0 0 1] ']

This creates one big string containing both parameter names and values.

> figure(1);
> plot(x,y,'-sb');
> figure(2);
> plot(x,y,'linestyle','-','marker','s','color',[0 0 1]);

Note that this is calling PLOT with eight input arguments. The first two are
numeric arrays, followed by three parameter name/value pairs.

> figure(3);
> plot(x,y,trace1);

This calls PLOT with three input arguments where the third is a valid
linestyle specification.

> figure(4);
> plot(x,y,trace2);

This too calls PLOT with three input arguments (like your third attempt) but
the string you pass in as the third input is NOT a valid linestyle.

One way to do what you want is to use a comma-separated list:

trace4 = {'linestyle','-','marker','s','color',[0 0 1]}
plot(x, y, trace4{:})

If you're interested in more information about comma-separated lists, search
the documentation and/or Loren's blog using that term as the keyword.

> All figures should be the same. In figure 1 and 2, I do not pass any
> argument but write them directly within the command plot. On figure 3, I
> can pass the line arguments using the short statement. In figure 4, I try
> to do the same but using the long statements. However, fig. 4 does not
> plot and I get the following error message:
> ??? Error using ==> plot
> Error in color/linetype argument
> Does anyone have an idea how I can pass these arguments using the long
> statements?

See above.

Steve Lord
To contact Technical Support use the Contact Us link on