Error assigning axes from array to xline

1 view (last 30 days)
I have a function that plots a set of 3 by 4 subplots. Inside of that function I sucessfully collate all axes from each individual subplot (12 in total) storing them in a cell array.
My goal is to create a plot like this:
However, this was plotted in the wrong subplot (last one): [subplot(3, 4, 12)]
while I need this to be in a specific one, based on the ax_array that contains all of the previous axes.
When I try to specify in which axes the line should be plotted from one of the axes in my array, (in this case plot_idx is 1) I get the following error:
Say, for instance, that I want the line to be drawn in the first axes which has the title "Capacitance REFLECTION'. Indeed, the first element of my array is the axes that I want to:
The parent from the xline I am trying to plot is an Axes! hoever, it has been assigned to the wrong one!
However, when attempting to assign the Parent as the desired element from my array (first one), I get the following error:
What am I missing here?

Accepted Answer

Daniel Melendrez
Daniel Melendrez on 12 Sep 2022
Guys. I am going to answer my own question.
I found the solution by myself minutes after posting this.
The solution was to save the axes from the subplots:
ax{i} = subplot(3, 4, idx)
I wasn't aware that subplot indeed creates axes! (n00b move, I know)
The problem was that I originally saved axes in the form:
ax{i} = gca
which created an array of axes, yes, but when reading back the contents they were stored as structs, so basically I was assigning a struct to an axes handle inside xline while it was expecting a graphic object.
My question now is, why saving the axes as ax{1} = gca and reading it back in the form:
ax_array{1}
doesn't keep it as axes object?
So, this is what I wanted originally:
and the plots as expected:

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!