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.
4 件のコメント
Rik
2019 年 3 月 28 日
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
2019 年 3 月 28 日
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.
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!