anon
anon

Reputation:

Pass parameter from gui to function

I'm trying to pass values from the interface to a function.

My run button in mygui.m:

function btnRun_Callback(hObject, eventdata, handles)
    handles.k.train = get(handles.txtTrain,'String');
    handles.k.test = get(handles.txtTest,'String');
    guidata( hObject, handles );

    test = process( handles.k);

My function (process.m):

function [ output_args ] = process( k)
     sprintf('tain=%s', k.train);
     sprintf('test=%s', k.test);
     output_args = 0;
end

Nothing is getting printed on the screen. I want the values from my two textboxes to be usable in the function.

Upvotes: 0

Views: 44

Answers (1)

Jørgen
Jørgen

Reputation: 863

When printing formatted strings to the screen, one can use fprintf in Matlab. Using fprintf without any fileID will print to standard output (i.e. the screen), where fileID=1.

>> fprintf('Hello World\n')
Hello World
>>

Setting fileID=2 means standard error, which will print the string in red.

Upvotes: 1

Related Questions