question_1
question_1

Reputation: 112

Pass values from GUI to m-file MATLAB

I m trying to pass values from two edittexts, when i press a buttom to my main m-file. I get the data from GUI but i can't call the main and pass the values there.That's what i have done till now. GUI(GUIDE )code

function resultbutton_Callback(hObject, eventdata, handles)
% hObject    handle to resultbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
N=str2num(get(handles.edituser,'String'));
f=str2num(get(handles.editfrequency,'String'));

What else should i write here and in main program. Should i use function in main? Thanks in advance

Upvotes: 0

Views: 829

Answers (1)

p8me
p8me

Reputation: 1860

Using inputdlg is probably the easiest way for you to get your job done.

... % Initialization

% Open a dialog box and wait for user to input two numbers.
dlg_title = 'Input';
num_lines = 1;
prompt = {'Input 1:','Input 2:'}; % label for each input
def = {'10','20'}; % default values of each input
answer = inputdlg(prompt, dlg_title, num_lines, def); % open dialog box

if ~isempty(answer) % only if OK button was clicked
    N = str2double(answer{1});
    f = str2double(answer{2});
end
... % Continue calculations

Note that if user closes the window, answer would be an empty cell.

There could be any number of inputs.

Upvotes: 1

Related Questions