Modify GUI textbox from another script file?

Hello,
I am trying to update the text of a textbox via another function that performs an operation/does something. So under my GUI Opening function I have the following.
function Example_OpeningFcn(hObject, eventdata, handles, varargin)
handles = guidata(hObject); % Care for the newest version explicitly!
Test(hObject, handles);
handles = guidata(hObject); % Get the version updated in myFunction!
% Update handles structure
guidata(hObject, handles);
And then my function Test is something like this.
function Test(source, args, handles, hObject, eventdata)
%text = get(handles.Textbox1, 'string');
text = ['It Worked'];
%set(handles.Textbox1, 'string', text);
handles.Textbox1 = text
guidata(hObject, handles);
h = msgbox('Completed');
end
I am having trouble initializing text properly from what is in the textbox already and then needing to add a line, something like 'It Worked,' and then display it in the textbox.
I have been referencing this article but have gotten stuck. https://www.mathworks.com/matlabcentral/answers/66386-how-to-modify-the-handles-structure-gui-from-an-external-function Any assistance is appreciated!!
My current error is Not enough input arguments.
Error in Test (line 6) guidata(hObject, handles);

 Risposta accettata

You call the function Test() by:
Test(hObject, handles);
but the definition of the function uses 5 input arguments:
function Test(source, args, handles, hObject, eventdata)
Then e.g. "handles" is not defined inside the function. The solution is to provide all required inputs in the calling.

1 Commento

The @ creates a function handle: While "onChannelData" would be a call to the function without inputs, "@onChannelData" is a pointer to the function.
If a function handle is used to define a callback, the function is called with 2 inputs automatically: The Source and the EventData. For your 4 inputs you need:
elOnChannelData = addlistener(rtReader, 'ChannelData', ...
{@onChannelData, handles, hObject});
to provide the 2 additional inputs also.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Financial Toolbox in Centro assistenza e File Exchange

Tag

Richiesto:

il 26 Ago 2017

Commentato:

Jan
il 27 Ago 2017

Community Treasure Hunt

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

Start Hunting!

Translated by