Variables from diagram do not exist after run

7 views (last 30 days)
From my script, I create a diagram, for instance an histogram2:
% X & Y, datamax are data from my project
figure()
title('Title')
subplot(212)
binwidth=4;
h = histogram2(X,Y,(max([X,Y])+1)/datamax,'DisplayStyle','tile','ShowEmptyBins','off');
c=colorbar;
c.Label.String = 'Colorbar label';
axis equal tight
title('Filtered histogram')
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:
>> h
h =
handle to deleted Histogram2
I don't understand. Why is my histogram deleted? Apologies if it is a newbie question.
  1 Comment
Liz Pozzo Di Borgo
Liz Pozzo Di Borgo on 9 Nov 2022
I realized that I can peek at the data from command window as long as the plot is open.

Sign in to comment.

Answers (1)

Steven Lord
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.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!