Variables from diagram do not exist after run
2 views (last 30 days)
From my script, I create a diagram, for instance an histogram2:
% X & Y, datamax are data from my project
h = histogram2(X,Y,(max([X,Y])+1)/datamax,'DisplayStyle','tile','ShowEmptyBins','off');
c.Label.String = 'Colorbar label';
axis equal tight
xlabel('X'); ylabel('Y ')
That works, my histogram displays, etc. But then, when I want to check the values and I click on h in my workspace, it's empty. It is a table containing all the appropriate fields (Data, X, Y, etc). But when I click on each of these fields, I get this: the variable h.Data does not exist.
If I go to the command window and type h:
handle to deleted Histogram2
I don't understand. Why is my histogram deleted? Apologies if it is a newbie question.
Steven Lord on 9 Nov 2022
The histogram handle h and its properties are tied to the existence of the histogram object in the figure window. If that histogram has been deleted (which would happen if, for example, the figure has been closed) then you will not be able to access the properties of that histogram from the handle.
Depending on what you're trying to do, if you need the properties but don't need or want the graphics object to be created call histcounts2 instead of histogram2. The two functions return different outputs (after all there is no graphics object for histcounts2 to return) but most of the inputs (not related to properties of the graphics object) that you can pass to one you can pass to the other.