When I run the main function from mscript, it puts the variables in the workspace which I can access them in GUI using "evalin". How do I put the variables in the GUI workspace without running the main mscript file from a command window?

1 vue (au cours des 30 derniers jours)
function PushMe_Callback(hObject, eventdata, handles)
set(handles.output_line,'String','I Got here');
Get_Length(Note_Vector,output,Counter,Total_num)
%------------------------------------------------------------
function Get_Length(Note_Vector,output,Counter,Total_num)
output = [ ];
while (1)
T = Total_num - Counter;
for j=1:T
[xml_input]=Get_Note(Note_Vector(j));
output = [output xml_input];
end
end
  1 commentaire
Jan
Jan le 13 Nov 2012
Please post the question in the section for the question, while the title should be a short title only.

Connectez-vous pour commenter.

Réponses (2)

Image Analyst
Image Analyst le 13 Nov 2012
Modifié(e) : Image Analyst le 13 Nov 2012
There are no functions in a script. And the variables in a script are put into the base workspace directly - you do not need to use evalin() or assignin() or anything like that. Conversely, a function in an m-file will put the variables into the private workspace of that function. They are used by the function and vanish when the function exits. You should not use evalin or assignin inside the function (except under some fairly rare situations). If you want some variables in the function to be returned to the calling routine, then you have to define one or more output arguments:
function [output1 output2] = Get_length(input1, input2, input3, etc)
  1 commentaire
Eric Letsolo
Eric Letsolo le 13 Nov 2012
I have done exactly that but it still returns an error. This are the functions that were implemented.
[output1,output2,output3]=main(input1); %
function [d b] =Song(output1,output2,output3)
function Play_Song_Callback(hObject, eventdata, handles)
% hObject handle to Play_Song (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% pause off
set(handles.SheetStatus, 'String', 'Playing');
[d b] =Song(output1,output2,output3)
sound(d,b);
Error in AMNR (line 42)
gui_mainfcn(gui_State, varargin{:});
Undefined function or variable 'output1'.
Error in AMNR>Play_Song_Callback (line 252)
[d b] =Song(output1,output2,output3)

Connectez-vous pour commenter.


Jan
Jan le 13 Nov 2012
The function guidata can store variables inside the ApplicationData of a figure, such that they are available in all callbacks. You find guidata in the help and doc of Matlab and hundreds of examples in this forum.
  3 commentaires
Jan
Jan le 13 Nov 2012
@Eric: The code you have posted does not contain the variable "output1", which appears in the error message. But without seeing the line, which causes the error, we cannot guess the cause of the problem.
Eric Letsolo
Eric Letsolo le 13 Nov 2012
Modifié(e) : Eric Letsolo le 13 Nov 2012
[output1,output2,output3]=main(input1); %
function [d b] =Song(output1,output2,output3)
function Play_Song_Callback(hObject, eventdata, handles)
% hObject handle to Play_Song (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% pause off
set(handles.SheetStatus, 'String', 'Playing');
[d b] =Song(output1,output2,output3)
sound(d,b);
Error in AMNR (line 42)
gui_mainfcn(gui_State, varargin{:});Undefined function or variable 'output1'.
Error in AMNR>Play_Song_Callback (line 252)
[d b] =Song(output1,output2,output3)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by