How to run multiple instances of the same gui using a loop?

Hello,
I am quite new to Matlab GUI and would like to use a "for" loop to generate several times the same gui but with different data inside. For instance, let's take the following case:
I have generated a simple GUI with a unique "Static Text" component inside. I would like the Static text to be updated in a new window at each iteration of the for loop (I have just added the following line under the Output function pasted from the testGUI2.m code):
set(handles.text1,'String',Hello(j));
(and I have also set : gui_Singleton = 0; at beginning)
And I simply want to do something like this: (in another code)
%%TEST GUI Loop
global Hello
Hello = {'hello1';'hello2';'hello3'};
for j = 1:length(Hello)
testGUI2(j)
end
I expect that the code pops up three windows (of the same GUI) with "hello1" in the first, "hello2" in the second and "hello3" in the third.
Can someone help me?
Many thanks in advance for your time and consideration.
Bari

1 Comment

Oh sorry the displayed question is not in the same format. I meant:
%%TEST GUI Loop
global Hello
Hello = {'hello1';'hello2';'hello3'};
for j = 1:length(Hello)
testGUI2(j)
end

Sign in to comment.

 Accepted Answer

Bari - rather than using a global variable array, just pass that string into the call to testGui2 as
for j = 1:length(Hello)
testGUI2(Hello{j});
end
and then make use of that input string in the testGUI2_OpeningFcn (not the Output function) as
function testGUI2_OpeningFcn(hObject, eventdata, handles, varargin)
% varargin is the variable array of input arguments and will have your
% input to this function
handles.output = hObject;
guidata(hObject, handles);
% update the text field
set(handles.text1,'String',varargin{1});
Try the above and see what happens!

1 Comment

Hi Geoff,
Yeah it works perfeclty fine. Many thanks for your help!
Bari

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!