Reputation:
I have three files in Matlab:
mygui.fig
mygui.m
mycode.m
As the titles suggest, the first two deal with the simple user interface and the last is where my processing takes place.
I have created mygui.fig
using GUIDE and it looks like this:
When I hit run, I want the two parameters from the interface to be transferred to mycode.m
.
I currently have this code in mygui.m
which captures the data from the textboxes:
function btnRun_Callback(hObject, eventdata, handles)
strPathTrain = get(handles.txtPathTrain,'String');
strPathTest = get(handles.txtPathTest,'String');
mycode.m
looks like this:
Trainset = 'C:\Users\blah1';
Testset = 'C:\Users\blah2';
...
How can I call and transfer these values to mycode.m
?
Upvotes: 0
Views: 77
Reputation: 1389
You can transfer data among them using handles, try it this way.
For example, in the form code:
handles.k.tr = get(handles.txtTr,'String');
handles.k.te = get(handles.txtTe,'String');
guidata( hObject, handles );
somefunction( handles.k );
The function:
function [ output_args ] = somefunction( k )
fprintf('tain=%s', k.tr);
output_args = 0;
end
Upvotes: 2
Reputation: 193
You can create a global structure to store all user inputs in mygui.m
and use that in other functions.
Alternatively, you can also write the value to a file inside the function and read process the file elsewhere.
Upvotes: 1