Input data using GUI
显示 更早的评论
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 个评论
abouessire ismail
2019-3-28
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
2019-3-28
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
2019-3-28
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
2019-3-28
Jordy Charly Isidore RABETANETIARIMANANA
2019-3-28
采纳的回答
更多回答(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.
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!