Adding Callback to stackedplot

1 visualizzazione (ultimi 30 giorni)
Maximilian Schulte
Maximilian Schulte il 7 Apr 2024
I'm currently writing a class that is using a stackedplot to display a selected rows of a Timetable. You are loading a big Timetable into the stackedplot, after that you can set the rows of the timetable that will be displayed via a gui. The problem is, that once it's set you can not recall the gui to set the DisplayVariables of the stackedplot again. Is there any way to add a callback to my class or the stackedplot so that i cann call the function that recalls the gui.
Options i already thougt of were either adding a tool to the axis toolbox or working with listeners, but i couldn't get any of those to run.

Risposte (1)

Pratyush
Pratyush il 8 Apr 2024
Hi Maximilian,
I guess one straightforward way to achieve this is by adding a UI control (e.g., a button) to your figure that, when clicked, invokes the GUI for selecting "DisplayVariable".
Here is an example script that may help.
function createInteractiveStackedPlot(TT)
% Create a figure
f = figure;
% Create a stacked plot
sp = stackedplot(TT);
% Add a button for adjusting DisplayVariables
btn = uicontrol('Style', 'pushbutton', 'String', 'Change Variables',...
'Position', [20 20 150 20],...
'Callback', @changeDisplayVariables);
function changeDisplayVariables(src, event)
% Callback function to invoke GUI for changing DisplayVariables
% Here, you would implement or call your GUI for selecting variables
disp('Implement your GUI logic here');
% Example: Update DisplayVariables (You'll replace this with GUI logic)
sp.DisplayVariables = TT.Properties.VariableNames(randperm(width(TT), 3));
end
end
  1 Commento
Maximilian Schulte
Maximilian Schulte il 8 Apr 2024
Thanks, i also think that implementing this will be quite easy as you said, but i'd love to have a cleaner solution regarding optical apperance. I also thougt of adding a context menu but that did not work either

Accedi per commentare.

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by