Keep GUI functions running when opening an uigetfile Dialog?

1 vue (au cours des 30 derniers jours)
Manuel Thomet
Manuel Thomet le 20 Mai 2015
Commenté : Manuel Thomet le 20 Mai 2015
I have made a GUI "Recording" which displays real time data from Simulink on several axes.
Within this GUI "Recording" I placed a pushbutton which opens another GUI "TrendFunction" where I can display a trend function. (E.g. the data over the last 2, 5 or 10 minutes)
Now, the problem is that within the "TrendFunction" I use uigetfile() to load data. But this causes my Simulink model and thereby the recording to stop. (Both the Simulink model and all axes in "Recording" do not continue/update) It seems that all functions are set on hold until the uigetfile() dialog is closed.
So the Question is:
Is there a way to avoid holding/pausing a Simulink model when opening an uigetfile dialog in a GUI?

Réponse acceptée

Alfonso Nieto-Castanon
Alfonso Nieto-Castanon le 20 Mai 2015
Modifié(e) : Alfonso Nieto-Castanon le 20 Mai 2015
No, as far as I know uigetfile will create a modal window (see windowstyle) which will lock matlab interface until a selection is made (and the selected filename can be returned to your originating function/script). In order to avoid this you need a non-modal file selection routine. For example, you may want to create your own display showing the available data files, and create a callback function that will implement the desired trend display once the user has selected a file. For example something based on the following:
function TrendFunction(varargin)
files = dir('*.mat');
h_fig = figure;
h_dlg = uicontrol('style','listbox','units','norm','position',[.1 .1 .8 .8],'string',{files.name},'callback',@TrendFunction_selected);
% that is all, now return control to Matlab until a selection is made
end
function TrendFunction_selected(varargin)
% when a file selection is made:
files = get(gcbo,'string');
selected = get(gcbo,'value');
file = files{selected};
data = load(file);
% here the plotting functions
clf(gcbf);
h_ax = axes('parent',gcbf);
plot(h_ax, data.x, data.y);
end
You can make that prettier but that should give you an idea of the code flow...
  1 commentaire
Manuel Thomet
Manuel Thomet le 20 Mai 2015
Yes this works. Did somehow not think of creating it on my own.
Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (1)

Thomas Koelen
Thomas Koelen le 20 Mai 2015
Modifié(e) : Thomas Koelen le 20 Mai 2015
Try calling a function that calls the uigetfile function, maybe this works but I'm not sure.
  1 commentaire
Manuel Thomet
Manuel Thomet le 20 Mai 2015
I like the idea.
Tried it, but did not succeed.
(pushbutton callback calls a function "outside" the GUI to get the file)
It seems as if it does not matter where the uigetfile is called, it still blocks my Model. I assume explicitly running it in parallel could work for me. (Multithreading?) Can I do that?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by