How to store function parameters in a single variable

43 views (last 30 days)
I would like to store the options for my plot command in a single variable at the beginning of the m-file, so that I can easily change the ploting parameters for all plots before I run the file. My sample code is as follow:
LinesMarker={'-rv'; '-bs'; '-g+';'-c*';'-mh'};
PlotOpt={LinesMarker{x},'DisplayName','FName{x}(1:end-4)','MarkerSize','5','LineWidth','1'}
FName{1}='F1_50Hz_1A.txt'
FName{2}='F1_50Hz_2A.txt'
FName{3}='F2_75Hz_1A.txt'
a=1:1:10;
b{1}=2.*a;
b{2}=3.*a;
b{3}=4.*a;
%
figure
for x = 1:3
plot (a,b{x},PlotOpt);
hold on
legend1 = legend('show','-DynamicLegend');
end
I get the following error:
Error using plot Conversion to double from cell is not possible.
Is there a function or another way to extract a cell with different types (string and numbers) to a list of arguments?
Thanks a lot in advance for any help or tip!

Accepted Answer

José-Luis
José-Luis on 29 May 2013
You could use a structure instead.
PlotOpts.LineStyle = '-.';
PlotOpts.Color = [0 1 0];
PlotOpts.Marker = 's';
PlotOpts.MarkerSize = 5;
PlotOpts.LineWidth = 2;
plot(rand(10,1),PlotOpts)
Not that the title and the legend are not lineseries properties so you would have to set them where it corresponds.
  6 Comments
Andreas
Andreas on 30 May 2013
Thanks again lot for your answer. Saving the structure in a cell array is doing the job for me. I did not know that I have to use round brackets when saving the structure to the cell.
I will mark the problem solved. Thanks a lot!

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!