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);

 採用された回答

Jan
Jan 2017 年 8 月 26 日

0 投票

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 件のコメント

Jan
Jan 2017 年 8 月 27 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFinancial Toolbox についてさらに検索

タグ

質問済み:

2017 年 8 月 26 日

コメント済み:

Jan
2017 年 8 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by