MATLAB Answers

Using dendrogram in App Designer

11 views (last 30 days)
I'm trying to integrate a dendrogram in to my App in App Designer.
However i can't seem to find a way to plot the dendrogram into the grap within the App.
This is my code:
X = table2array(t);
Z = linkage(X,'single','euclidean');
dendrogram(app.UIAxes,Z);
It seems that the sytax
dendrogram(app.UIAxes,Z);
does not work. Is there a workaround? Maybe a way to use plot() instead of dendrogram().
Thank you very much!
Chris

Accepted Answer

Adam Danz
Adam Danz on 30 Dec 2020
The problem is that this plotting function does not allow you to supply an existing axes handle as input so it relies on finding the current axes. By default, the handle visibiliity of UIFIgures is off so the axes within those figures are not discoverable.
From r2020a and later, you need to set the app's handle visibility to on so that the app's axes can be detected as "current". Then make the app's axes "current". Then, you can run the plotting function which will access your app's axes.
% app.UIFigure is the handle to your app's figure
% app.UIAxes is the handle to the app's axes
% 1) Turn on the app figure's handle visibility.
app.UIFigure.HandleVisibility = 'on';
% 2) Make the app's axes current
set(0, 'CurrentFigure', app.UIFigure)
set(app.UIFigure,'CurrentAxes',app.UIAxes)
% 3) call the plotting function
dendrogram(__);
% 4) set app figure handles back to invisible (optional, but recommended)
app.UIFigure.HandleVisibility = 'off';

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!