Using MATLAB Notation to Set Multiple Properties Simultaneously

Recently, MATLAB has been activating handles to use dot notation to set properties.

eg.

set(plotLeft,'marker','o');

      

now maybe

plotLeft(1).Marker = 'o';

      

Can I use this new dot notation to set multiple fields at once. Below is the sample code below:

clc; clear all;
x = logspace(-3,0,100)';
plot1 = sin(x);
plot2 = cos(x);
[hax,plotLeft,plotRight] = plotyy(x,[plot1 plot1],x,[plot2 plot2])
plotLeft(1).Marker = 'o';
plotLeft(2).Marker = 'x';

      

I would like to set this bit:

plotLeft(1).Marker = 'o';
plotLeft(2).Marker = 'x';

      

But on one line. I can access the marker types:

plotLeft([1 2]).Marker

      

But that won't let me install them, as I think it will work:

>> plotLeft([1 2]).Marker = ['o' 'x']
Insufficient number of outputs from function on right hand side of equal sign to
satisfy overloaded assignment.

      

sample plot

+3


source to share


1 answer


You can use deal

to achieve this goal:

[plotLeft([1 2]).Marker] = deal('o', 'x');

      



plotLeft([1 2]).Marker

creates a comma separated list , so you cannot assign it directly, but you can use a deal to handle it, this would be the equivalent of this:

[plotLeft(1).Marker, plotLeft(2).Marker] = deal('o', 'x');

      

+6


source







All Articles