Execute .m file using GUI

I would like to run a .m file by using pushbutton in GUI, the .m file output is an array which is not loaded in the workspace. Is there anyway to execute .m file using GUI or to load the output.
Thanks, Arif

 采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-10-19

0 个投票

Is your .m file a function or a script? You need to understand the difference. Functions and Scripts.
If it is a function, you can use output argument to pass in the data. If it is a script, you can run the .m file directly with the GUI function callback to set up the data, although this approach is not recommended.

4 个评论

Thanks for reply.But I am facing the same problem-
I want to make a GUI which has a push button and in the workspace there is a Matrix A.I want that whenever I click on the push button it will take the Matrix A manipulate matrix according to the code and then output the matrix on the workspace.But it is not happening because whenever I click the push button code run but new matrix is not displaying on the workspace.Could you please help me for that.I am sending you the code which I have written in push button function-
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
modified_data=cell2mat(evalin('base','data_to_be_exported'));
i=1;n=1;A=zeros(size(modified_data));d=1;
for (n=1:size(modified_data,2))
if(modified_data(1,n)==',')
A(1,i)=n;i=i+1;
n=n+1;
else n=n+1;
end
end
p=size(modified_data,2);
for(m=1:p)
if(A(1,m))>0
p=p+1;
else end
end
size_of_the_finalarray=p-m;
l=1;
string='0';
Final_Array{1,1}='voltage';
Final_Array{1,2}='Time';
Final_Array{1,3}='S.No';
for(x=1:A(l))
string=strcat(string,modified_data(x));
end
Final_Array{2,1}=string;
string='0';
for(x=A(l):A(2))
string=strcat(string,modified_data(x));
end
Final_Array{2,2}=string;
string='0';
for(x=A(2):A(3))
string=strcat(string,modified_data(x));
end
Final_Array{2,3}=string;
for(l=4:size_of_the_finalarray)
string='0';
for(x=A(l-1):A(l))
string=strcat(string,modified_data(x));
end
if(rem(l,3)==1)
Final_Array{2+(l-1)/3,1}=string;
else if(rem(l,3)==2)
Final_Array{2+(l-2)/3,2}=string;
else Final_Array{2+(l-3)/3,3}=string;
end
end
end
Final_Array=strrep(Final_Array,'0,',' ');
Final_Array=strrep(Final_Array,'0+',' ');
Final_Array=strrep(Final_Array,'NVDC,',' ');
Final_Array=strrep(Final_Array,'secs,',' ');
Final_Array=strrep(Final_Array,'RDNG#,',' ');
Final_Array=strtrim(Final_Array);
%xlswrite('sample.xls',Final_Array);
%xlswrite('sample.xls',Final_Array);
xlswrite('test.xls',evalin('base','Final_Array'))
Thanks
Arif
Again, follow the link in my answer to understand the base workspace and function workspace. Your variable 'data_to_be_exported' is in base workspace. So you use evalin('base',...) to make it available in the function workspace. That is right. The result 'Final_Array' is in function workspace. You need to run 'xlswrite('sample.xls',Final_Array)', not 'xlswrite('test.xls',evalin('base','Final_Array'))'. What is wrong with the above code. What is wrong with your initial attempt using 'xlswrite('sample.xls',Final_Array)'?
If you want to make Final_Array available in base workspace, run this at the end of the function.
assignin('base','Final_Array',Final_Array);
Thank you very much.This is what I want.It solved my problem.
-Arif Khan

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by