Input data using GUI
Mostra commenti meno recenti
I am working on a sensitivity analysis using EFAST method, i want to build an interface for this model. I want to ask the users to enter the number of frequency = n that they want, after that I want them to input the value of the n frequencies. Here is the program outside of GUI
n= input ('enter the number of frequency:');
for i=1:n
f(i)=input(['enter the frequency number', num2str(i),':']);
end
How to do it with GUI
5 Commenti
abouessire ismail
il 28 Mar 2019
Hi .
i hope that my answer can solve your problem .
firstly create a gui that contain an edit text to get the number of frequency that are stored in a variable by the next instruction :
temp1=str2double(get(hObject,'String'));
assignin('base','n',temp1); %get number from the gui to workspace.
% if you set in edit text a caracter you should give you a messageBox.
if isnan(temp1)
errordlg('set please a number not a caracter !!!','File Error');
end
secondly,we create in the same gui a button that contain in button_callback :
n= evalin('base','n'); %from worksapce to gui;
for i=1:n
f(i)=input(['enter the frequency number', num2str(i),':']);
end
that's it.
Have a nice day.
Rik
il 28 Mar 2019
Do not use evalin. Write a function that opens a modal box instead. Look into the uicontrol, uiwait and guidata functions. I'll write up a function for you in a while.
Adam
il 28 Mar 2019
Using input in a GUI doesn't make sense - that is for keyboard input. If you have a GUI then have GUI components ask the user for any inputs. I'll assume Rik's solution will cover things though so I won't add any more!
Jordy Charly Isidore RABETANETIARIMANANA
il 28 Mar 2019
Jordy Charly Isidore RABETANETIARIMANANA
il 28 Mar 2019
Risposta accettata
Più risposte (1)
Do you want to create the GUI in AppDesigner, in GUIDE or programmatically? With the last one:
function Data = YourGUI
H.Fig = figure('Position', [100, 100, 300, 640]);
H.Edit = uicontrol(H.Fig, 'Style', 'edit', 'String', '', ...
'Position', [10, 610, 280, 25], ...
'Callback', @EditCB);
H.Ready = uicontrol(H.Fig, 'Style', 'PushButton', 'String', 'Ready', ...
'Position', [210, 10, 80, 25], ...
'Callback', @ReadyCB);
H.Table = uitable(H.Fig, 'Position', [10, 35, 280, 580], 'Visible', 'off');
guidata(H.Fig, H);
uiwait(H.Fig);
Data = H.Table.Data;
end
function EditCB(EditH, EventData)
H = guidata(EditH);
n = sscanf(EditH.String, '%d', 1);
set(H.Table, 'Data', cell(n, 1), 'Visible', 'on');
set(EditH, 'Enable', 'off');
end
function ReadyCB(ButtonH, EventData)
H = guidata(ButtonH);
uiresume(H.Fig);
end
UNTESTED CODE - debug this by your own.
4 Commenti
Rik
il 28 Mar 2019
A table might be a better idea than a plain edit field. For the rest it is funny to see how much we agree on the approach.
Rik
il 28 Mar 2019
I meant your use of uitable instead of my uicontrol edit style. A table trades some space for more clarity that you need to enter values.
Categorie
Scopri di più su Structures in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!