How to store function parameters in a single variable

25 visualizaciones (últimos 30 días)
Andreas
Andreas el 29 de Mayo de 2013
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!

Respuesta aceptada

José-Luis
José-Luis el 29 de Mayo de 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 comentarios
Andreas
Andreas el 30 de Mayo de 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!
José-Luis
José-Luis el 30 de Mayo de 2013
Glad to help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by