How to Assign an Axes Object to a struct?

2 views (last 30 days)
It seems that MATLAB automatically assign h2Axes to struct G, not hAxes. How can I specifically assign hAxes to struct G?
hAxes = axes('NextPlot', 'add', 'XLim', [0, 20], 'YLim', [-1, 10], 'Position', [0 0 0.5 0.5]);
h2Axes = axes('NextPlot', 'add', 'XLim', [0, 20], 'YLim', [-1, 10], 'Position', [0.5 0.5 0.5 0.5]);
W = 4;
Y = 0;
H = 8;
for i = 1 : 3
X = i.* W;
R = rectangle;
R.Position = [X Y W H];
G(i).r = R;
end

Accepted Answer

Jan
Jan on 22 Feb 2017
Edited: Jan on 22 Feb 2017
hAxes = axes('NextPlot', 'add', 'XLim', [0, 20], 'YLim', [-1, 10], 'Position', [0 0 0.5 0.5]);
h2Axes = axes('NextPlot', 'add', 'XLim', [0, 20], 'YLim', [-1, 10], 'Position', [0.5 0.5 0.5 0.5]);
W = 4;
Y = 0;
H = 8;
for i = 1 : 3
X = i.* W;
R = rectangle('Parent', hAxes);
% Or:
% R.Parent = hAxes;
R.Position = [X Y W H];
G(i).r = R;
end

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!