There are different ways in which you can send output to the base workspace from a GUI.
You can make use of the output function of the GUI. For example, when you create a GUI with the name ‘mygui’ using GUIDE and save it, GUIDE will automatically create a ‘mygui.m’ file. One of the sub-functions in ‘mygui.m’ will be the ‘main_OutputFcn’ which can be edited to send meaningful output to the workspace. Please refer to the demo video in the following webpage for more information:
<http://blogs.mathworks.com/videos/2010/02/12/advanced-getting-an-output-from-a-guide-gui/>
In order to pass the required variable to the output function, you can make use of the SETAPPDATA and GETAPPDATA. Please refer to the documentation pages for the above functions for additional information about their usage.
With your GUI open in GUIDE, right click on the UITABLE and select View Callbacks->CellEditCallback.
Add the following lines to the uitable's Cell Edit Callback function:
A=get(hObject,'Data');
B=cell2mat(A);
dotPr=dot(B(1,:),B(2,:));
Setappdata(hObject,‘result’, dotPr);
Modify the output function ‘main_OutputFcn’ in the following manner to return ‘result’ to the workspace:
function varargout = main_OutputFcn(hObject, eventdata, handles)
varargout{1} = getappdata(hObject,’result’);
An alternative solution is to use the function ASSIGNIN to output the data from GUI to workspace. Refer to the corresponding documentation page for more information about the function.
If using ASSIGNIN, you can modify the ‘CellEditCallback’ of the UITABLE as follows:
A=get(hObject,'Data');
B=cell2mat(A);
dotPr=dot(B(1,:),B(2,:));
assignin('base','result',dotPr)
You might find the following documentation pages about data management in a GUIDE GUI and a Programmatic GUI useful:
<http://www.mathworks.com/help/releases/R2013a/matlab/creating_guis/ways-to-manage-data-in-a-guide-gui.html>
<http://www.mathworks.com/help/releases/R2013a/matlab/creating_guis/ways-to-manage-data-in-a-programmatic-gui.html>
Best Answer