Adding Callback to stackedplot

1 回表示 (過去 30 日間)
Maximilian Schulte
Maximilian Schulte 2024 年 4 月 7 日
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.

回答 (1 件)

Pratyush
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
  1 件のコメント
Maximilian Schulte
Maximilian Schulte 2024 年 4 月 8 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by