Clear Filters
Clear Filters

Callback issue with uimenu when while loop has been executed

1 view (last 30 days)
I have this code (highlights)
function alles_trial
S.Properties.VariableNames{1} = 'T';
S.Properties.VariableNames{2} = 'I';
m = uimenu(f1,'Text','Plot options');
uimenu(m,'Text','Save and close plot','Callback',@close_everything);
function close_everything(~,~)
close all;
writetable(p, ext_alles_event_parameters,'Sheet',1);
writetable(m, fullFileName_table_nr_event, 'Delimiter', '\t');
m2 = uimenu(f1,'Text','Frames');
uimenu(m2,'Text','Next 5 seconds','Callback',@next_frame);
function next_frame(~,~)
[limit,~]=find(lastx == S.T);
plot(x, y, 'Color', 'b');%plot the variables.
[0.0678571428571429 0.48125 0.871428571428572 0.44375]); %position for the plot
plot(x, y, 'Color', 'b');%plot the variables.
while cont==1
[px_1,~] = myginput(2,'crosshair');
I import the file (readtable) and plot part of it (x=S.T(1:100000); y=S.I(1:100000); plot(x, y, 'Color', 'b'). Then, I select 2 ROIs (myginput) and calculate some parameters over this specific section of the plot. When finish, I want to update the plot by taking the next 100000 values of the table. This procedure is continued until the end of the table.
Callback @next_frame works until I click in the plot: When I click in the plot (myginput function) I cannot call the callback @next_frame (it remplaces the previous plot taking the next 100,000 values from a 5,000,000x1 table) but the callback @close_callback works.
I tried to use a button to update the plot, but uifigure and app design do not like myginput function. Therefore, I have to use this workaround (uimenu).

Answers (1)

arushi on 9 May 2024
Hi Jose,
As per my understanding, the issue arises from the interaction between "myginput" and the GUI elements (like uimenu) in your MATLAB figure. When "myginput" is called to select regions of interest (ROIs) on the plot, it likely interferes with the normal event handling mechanism of the figure, making it unresponsive to further uimenu callbacks until the "myginput" operation is completed.
One approach to mitigate this issue is to modify the workflow to ensure that "myginput" does not block the GUI's event loop or to use an alternative method for selecting ROIs :.
  1. Use a Non-blocking Approach for ROI Selection: Instead of using "myginput" directly in the event loop, consider using interactive tools like drawrectangle, drawline, or other draw functions that do not block MATLAB's event processing. These functions allow users to draw shapes directly on plots to define ROIs and can be used in a non-blocking manner.
  2. Implement a "Confirm Selection" Mechanism: After drawing the ROI using the interactive tools, you can add a "Confirm Selection" button to your figure that, when clicked, processes the selected ROIs. This separates the ROI selection process from the data processing and allows the figure to remain responsive.
For more information on drawrectangle function, please refer to the MathWorks documentation-
Hope this helps.


Find more on Interactive Control and Callbacks 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!