Setting a value for multiple axes handles at once (without a for-loop)

3 views (last 30 days)
Hey all,
As the title suggests, I'm trying to prevent a for-loop in the following problem. Im working in MATLAB 2019b
I defined three subplots, and from each ylabel, I would like to get the minimum x-position. Here is a minimum working example, which does not work. But it identifies and explains my problem, see the added script. The final two lines don't work for the same reason.
The reason I'm into this problem is because I want to align my ylabels. Therefore, If a know the minimum value of one label, I can set the other labels to the same value.
Anyone who can help me with this problem?
Thanks in advance!
Gerard
figure
s1 = subplot(3, 1, 1);
s2 = subplot(3, 1, 2);
s3 = subplot(3, 1, 3);
axs(1) = ylabel(s1, '...');
axs(2) = ylabel(s2, '...');
axs(3) = ylabel(s3, '...');
axs(:).Units = 'centimeters';
mxP = min(axs(:).Position(1));

Accepted Answer

Sindar
Sindar on 14 Feb 2020
Setting a value for multiple handles is pretty easy:
set(axs,'Units','centimeters')
getting values is a little trickier. For your particular problem, the following works:
% concatenate the positions of all the axes
tmp=[axs.Position];
% find the min from the first position values
mxP = min(tmp(1:3:end));

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!