How to store function parameters in a single variable

조회 수: 22 (최근 30일)
Andreas
Andreas 2013년 5월 29일
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!
José-Luis
José-Luis 2013년 5월 30일
Glad to help!

댓글을 달려면 로그인하십시오.

추가 답변 (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