How do I input data using GUI inside a loop?

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.

 Akzeptierte Antwort

Matt Fig
Matt Fig am 22 Mär. 2011

1 Stimme

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 Kommentare

Liqing
Liqing am 22 Mär. 2011
Thank you very much for the help. It's great to learn a new function called INPUTDLG. It is surely much better than uicontrol here.
btw, I like your red neck avatar :-)
Matt Fig
Matt Fig am 22 Mär. 2011
That is funny! What is redneck about it, may I ask? Is it the flag? The picture was taken in a schoolroom, not out in a pasture ;-).
Liqing
Liqing am 22 Mär. 2011
The flag, the beard, and the big arms. I lived in the south for 7 years. I surely had fun with them. That said, red neck is a very positive word to me.
Red neck working on matlab is a cute thing :-)
Matt Fig
Matt Fig am 22 Mär. 2011
Haha, my mama would be proud...
Liqing
Liqing am 22 Mär. 2011
She surely should. Thank you again for the help. You are the best!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 22 Mär. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by