Consol Output to GUI
Show older comments
Dear all,
I try to get the output of the consol to the Gui. I wrote a small test which works fine for me starting it from matlab itself.
The Code (adapted it from https://de.mathworks.com/matlabcentral/answers/71078-command-window-output-to-gui) is below. I highleighted the "non-nomal" Gui stuff by the longer lines.
function varargout = testgui(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @testgui_OpeningFcn, ...
'gui_OutputFcn', @testgui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before testgui is made visible.
function testgui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = testgui_OutputFcn(hObject, eventdata, handles)
update_textfield(hObject, eventdata, handles) %--------------------------------------------------------------
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
clc;
handles.text2.String = get(handles.edit1,'String');
for i = 1:uint8(str2double(get(handles.edit1,'String')))
disp(num2str(i));
pause(0.1);
update_textfield(hObject, eventdata, handles); % ---------------------------------------------------------
end
function update_textfield(hObject, eventdata, handles) % -----------------------------------------------------
jDesktop = com.mathworks.mde.desk.MLDesktop.getInstance;
jCmdWin = jDesktop.getClient('Command Window');
jTextArea = jCmdWin.getComponent(0).getViewport.getView;
cwText = char(jTextArea.getText);
handles.text3.String = cwText;
function edit1_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
Everthing works fine so far. But using the application builder I get the following error message
Dot indexing is not supported for variables of this type. Error in => testgui.m at line 42
By using the individual lines of the code I found that it is caused by
jTextArea = jCmdWin.getComponent(0).getViewport.getView;
Are there any ideas on how to solve that problem?
Answers (0)
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!