Adding Callback to stackedplot
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Pratyush
2024-4-8
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!