Clear Filters
Clear Filters

How do I input data using GUI inside a loop?

1 view (last 30 days)
I want to enable people to input several parameters, such as the number of headerlines, for each run inside the loop, by creating a simple GUI.
for i =1:200;
file = ['data' num2str(i) '.txt'];
if exist(file)==2;
h = uicontrol('style','pushbutton', 'callback', '');
N = get(h, 'String');
[a b] = textread(file, '%f %f %f', 'headerlines', N);
end;
end;
My question is, how do I program uicontrol, so that when people click the button, it will simply continue the program, rather than callback another m file?
Thank you.

Accepted Answer

Matt Fig
Matt Fig on 22 Mar 2011
I would use an INPUTDLG here.
prompt = {'Enter the number of header lines:'};
name = 'Header lines..';
for i =1:200;
file = ['data' num2str(i) '.txt'];
if exist(file)==2;
N = inputdlg(prompt,name,1,{'1'});
% Now to turn NLINES from a cell, use:
N = N{1}
[a b] = textread(file, '%f %f %f', 'headerlines', N);
end
end
Although, as a user I would be bummed if I had to enter 200 header lines manually through a GUI each time through the loop. Perhaps it would be better to create a text file which has the number of header lines for each data file in it...
  5 Comments
Matt Fig
Matt Fig on 22 Mar 2011
Haha, my mama would be proud...
Liqing
Liqing on 22 Mar 2011
She surely should. Thank you again for the help. You are the best!

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps 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!