Invalid use of operator error - GUI

3 views (last 30 days)
Karim Khalid
Karim Khalid on 27 Oct 2021
Commented: Steven Lord on 27 Oct 2021
Hello, I keep getting an "invalid use of operator" error for line 293 below. I am not sure what the error is, since everything seems fine to me. Please lmk. The line is function pushbutton_start_Callback(hObject, eventdata, handles) towards the end of the code below. Please please help me!
function varargout = FlexSystemGUInew(varargin)
% FLEXSYSTEMGUINEW MATLAB code for FlexSystemGUInew.fig
% FLEXSYSTEMGUINEW, by itself, creates a new FLEXSYSTEMGUINEW or raises the existing
% singleton*.
%
% H = FLEXSYSTEMGUINEW returns the handle to a new FLEXSYSTEMGUINEW or the handle to
% the existing singleton*.
%
% FLEXSYSTEMGUINEW('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FLEXSYSTEMGUINEW.M with the given input arguments.
%
% FLEXSYSTEMGUINEW('Property','Value',...) creates a new FLEXSYSTEMGUINEW or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before FlexSystemGUInew_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to FlexSystemGUInew_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help FlexSystemGUInew
% Last Modified by GUIDE v2.5 27-Oct-2021 14:29:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FlexSystemGUInew_OpeningFcn, ...
'gui_OutputFcn', @FlexSystemGUInew_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 FlexSystemGUInew is made visible.
function FlexSystemGUInew_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to FlexSystemGUInew (see VARARGIN)
% Choose default command line output for FlexSystemGUInew
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FlexSystemGUInew wait for user response (see UIRESUME)
% uiwait(handles.figure1);
%% Serial Connection Settings
serialPorts=instrhwinfo('serial');
handles.nPorts=length(serialPorts.SerialPorts);
handles.serPorts = serialPorts.SerialPorts;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = FlexSystemGUInew_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in Auto.
function pushbutton_auto_Callback(hObject, eventdata, handles)
% hObject handle to Auto (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% Detector info
handles.d_num = get(handles.Detectors,'String');
%% Source info
handles.s_num = get(handles.Sources,'String');
%% Wavelength info
handles.wls = split(get(handles.Wavelengths,'String'));
handles.wls_num = length(handles.wls);
end
set(handles.pushbutton_start,'Enable','on')
guidata(hObject, handles);
% --- Executes on button press in pushbutton_SystemEnable.
function pushbutton_SystemEnable_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_SystemEnable (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
connection = 'Serial';
if strcmp(get(hObject,'String'),'System Disable') % currently disconnected
if strcmp(connection,'Serial') == 1
serConn=serial(handles.serPorts{3}); %'COM4'
set(serConn,'TimeOut', 3);
set(serConn,'BaudRate',115200)
set(serConn,'DataBits',8)
set(serConn,'Parity','none')
set(serConn,'FlowControl','none')
set(serConn,'Terminator','LF');
set(serConn,'StopBits',1);
end
try
%Open selected serial port, enable button functions
fopen(serConn);
handles.serConn=serConn;
%Send mode commands
configStr=':I:0';
fprintf(handles.serConn,'%s',configStr);
pause(1);
receiveText = fgets(handles.serConn);
set(handles.text_IncomingText,'String',receiveText)
set(handles.pushbutton_start,'Enable','on')
set(hObject,'String','System Enable')
handles.filePath = 0;
catch e
errordlg(e.message);
end
else % Disconnect after connecting
set(hObject,'String','System Disable')
set(handles.pushbutton_start,'Enable','off')
set(handles.text_IncomingText,'String','')
fclose(handles.serConn);
fclose(instrfind);
instrreset;
end
guidata(hObject, handles);
function Background_CloseRequestFcn(hObject, eventdata, handles)
if strcmp(get(handles.pushbutton_SystemEnable,'String'),'SystemDisable') % currently connected
fclose(handles.serConn);
fclose(instrfind);
instrreset;
end
delete(hObject);
pushbutton_start_Callback(hObject, eventdata, handles)
function edit_detectors_Callback(hObject, eventdata, handles)
% hObject handle to edit_detectors (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_detectors as text
% str2double(get(hObject,'String')) returns contents of edit_detectors as a double
% --- Executes during object creation, after setting all properties.
function edit_detectors_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_detectors (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_sources_Callback(hObject, eventdata, handles)
% hObject handle to edit_sources (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_sources as text
% str2double(get(hObject,'String')) returns contents of edit_sources as a double
% --- Executes during object creation, after setting all properties.
function edit_sources_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_sources (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_patch_Callback(hObject, eventdata, handles)
% hObject handle to edit_patch (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_patch as text
% str2double(get(hObject,'String')) returns contents of edit_patch as a double
% --- Executes during object creation, after setting all properties.
function edit_patch_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_patch (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_wavelengths_Callback(hObject, eventdata, handles)
% hObject handle to edit_wavelengths (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_wavelengths as text
% str2double(get(hObject,'String')) returns contents of edit_wavelengths as a double
% --- Executes during object creation, after setting all properties.
function edit_wavelengths_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_wavelengths (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_gain_Callback(hObject, eventdata, handles)
% hObject handle to edit_gain (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_gain as text
% str2double(get(hObject,'String')) returns contents of edit_gain as a double
% --- Executes during object creation, after setting all properties.
function edit_gain_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_gain (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_repeat_Callback(hObject, eventdata, handles)
% hObject handle to edit_repeat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_repeat as text
% str2double(get(hObject,'String')) returns contents of edit_repeat as a double
% --- Executes during object creation, after setting all properties.
function edit_repeat_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_repeat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_start.
function pushbutton_start_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function pushbutton_start_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_intensityR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_intensityR_Callback(hObject, eventdata, handles)
% hObject handle to edit_intensityR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_intensityR as text
% str2double(get(hObject,'String')) returns contents of edit_intensityR as a double
% --- Executes during object creation, after setting all properties.
function edit_intensityR_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_intensityR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_intensityG_Callback(hObject, eventdata, handles)
% hObject handle to edit_intensityG (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_intensityG as text
% str2double(get(hObject,'String')) returns contents of edit_intensityG as a double
% --- Executes during object creation, after setting all properties.
function edit_intensityG_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_intensityG (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_intensityB_Callback(hObject, eventdata, handles)
% hObject handle to edit_intensityB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_intensityB as text
% str2double(get(hObject,'String')) returns contents of edit_intensityB as a double
% --- Executes during object creation, after setting all properties.
function edit_intensityB_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_intensityB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_SendIntensity.
function pushbutton_SendIntensity_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_SendIntensity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
int_R = get(handles.edit_intensityR,'String');
int_G = get(handles.edit_intensityG,'String');
int_B = get(handles.edit_intensityB,'String');
configStr = sprintf(':$:%s:%s:%s',int_R,int_G,int_B);
fprintf(handles.serConn,'%s',configStr)
pause(0.5)
receiveText = fgets(handles.serConn);
set(handles.receivingText,'String',receiveText)
% --- Executes during object creation, after setting all properties.
function pushbutton_sendIntensity_CreateFcn(hObject, eventdata, handles)
% hObject handle to Sources (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function frequency_axes_Createfcn(varargin)
  3 Comments
Karim Khalid
Karim Khalid on 27 Oct 2021
It was a typo. I still get the same error without it.
Walter Roberson
Walter Roberson on 27 Oct 2021
I am not sure yet why it is happening, but what is happening is that MATLAB thinks that all of those function definitions are nested functions that it just hasn't seen a matching end for. And then at some point it hits the limit on the number of times you can nest a function definition, and starts saying that you have a syntax error.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 27 Oct 2021
You have
% --- Executes on button press in Auto.
function pushbutton_auto_Callback(hObject, eventdata, handles)
% hObject handle to Auto (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% Detector info
handles.d_num = get(handles.Detectors,'String');
%% Source info
handles.s_num = get(handles.Sources,'String');
%% Wavelength info
handles.wls = split(get(handles.Wavelengths,'String'));
handles.wls_num = length(handles.wls);
end
set(handles.pushbutton_start,'Enable','on')
guidata(hObject, handles);
Notice the end statement. MATLAB thinks that end is matching the function definition, and becomes convinced that you are defining nested functions all over the place.
  1 Comment
Steven Lord
Steven Lord on 27 Oct 2021
If any of the functions in a file end with an end then all the functions in the file must end with an end.
One tool to help identify this is smart indenting the code in the MATLAB Editor. When I do this the start of FlexSystemGUInew_OutputFcn (line 73) is indented at the same level as the body of FlexSystemGUInew_OpeningFcn (starting on line 48) and the starts of the functions get further and further indented as the file proceeds. By the time we get to frequency_axes_Createfcn that function definition line starts at column 109. The first function where Code Analyzer complains is pushbutton_start_Callback on line 293 and that starts at column 69.

Sign in to comment.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!