0
votes

In Octave, when I plot I can get the plot object. For example

pl = get(plot(...))

I can then specify the labels such as:

xlabel("something")

I'm working on an auto-grader and need to check the contents of the xlabel from the plot object pl. I'd think I'd be able to say something like

disp(all(pl.xlabel == "something"))

But, I'm getting an error saying xlabel doesn't belong to the plot object.

1
What is the actual error? - excaza
Matlab switched from function syntax (e.g. get(graphics_object, field) to "struct syntax" (e.g. graphics_object.field ) some time in the last couple of years and currently supports both syntaxes. Octave may support "struct syntax" in the future, but for now only supports the "function syntax". Hence pl.xlabel does not apply in octave. Use the get / set functions on the appropriate objects that have the fields you're interested in instead (which is what you inadvertently show in your answer). - Tasos Papastylianou
You could try an approach using findobj() I showed here: stackoverflow.com/questions/47262876/…. I guess you can modify it to find label strings too. - Georg W.
@excaza The error was that xlabel is not a member of the plot handle. - mattsap

1 Answers

0
votes

If there is only one axis object, you could get the current axis object with gca, then get the labels and such through the axis object.

ax = gca
disp(get(get(ax, "XLabel") "String"))

If you have multiple plots on different figures and no handle to the figure, you could do the following where you get the figure, rather than directly use gca:

p1 = plot((1:10).^2);
p2 = plot((1:10).^4);
xlabel('Matt');
fig = ancestor(p1, 'figure');
ax = get(fig, "CurrentAxes");
disp(get(get(ax, "XLabel") "String"))