Adding Callback to stackedplot
3 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Pratyush
on 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
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!