How to store function parameters in a single variable

43 次查看(过去 30 天)
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!

采纳的回答

José-Luis
José-Luis 2013-5-29
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 个评论
Andreas
Andreas 2013-5-30
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by