Undefined Operators for input arguments of type 'struct'?
1 view (last 30 days)
Show older comments
Basically I want the user defined inputs to be considered and for the calculations and for the pushbutton to carry out the plotting. Sit tight because there is A LOT of problems in this code:
function varargout = CEN320Project(varargin)
% CEN320PROJECT MATLAB code for CEN320Project.fig
% CEN320PROJECT, by itself, creates a new CEN320PROJECT or raises the existing
% singleton*.
%
% H = CEN320PROJECT returns the handle to a new CEN320PROJECT or the handle to
% the existing singleton*.
%
% CEN320PROJECT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CEN320PROJECT.M with the given input arguments.
%
% CEN320PROJECT('Property','Value',...) creates a new CEN320PROJECT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before CEN320Project_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to CEN320Project_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 CEN320Project
% Last Modified by GUIDE v2.5 03-Dec-2019 02:50:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @CEN320Project_OpeningFcn, ...
'gui_OutputFcn', @CEN320Project_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 CEN320Project is made visible.
function CEN320Project_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 CEN320Project (see VARARGIN)
% Choose default command line output for CEN320Project
handles.output = hObject;
handles.edit1=0;
handles.edit2=0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes CEN320Project wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = CEN320Project_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.edit1=handles.edit1 +1
handles.edit2=handles.edit2 +1
guidata(hObject,handles)
N=guidata(hObject)
time=guidata(hObject)
recObj = audiorecorder(1000,16, 1);
record_time = 5;
recordblocking(recObj, record_time);
myECG = getaudiodata(recObj);
save('mydata')
y=myECG
Y=fft(myECG);
mag=abs(Y);
fs=500;
ecg=y();
for k=1:N;
ang(k) = inv(tan(imag(Y(k))/real(Y(k))*pi/180));
end
sum=0;
t=0:0.01:N;
for h=1:N
sum=sum+Y(h)*exp(1i*2*pi*(500/N)*t);
end
axes(handles.axes1)
plot(t,myECG)
title('ECG Signal')
xlabel('t')
ylabel('Amplitude')
grid on
axes(handles.axes2)
plot(t,mag)
title('Magnitude Spectrum')
xlabel('n')
ylabel('Magnitude')
grid on
axes(handles.axes3)
plot(t,ang)
title('Phase Spectrum')
xlabel('n')
ylabel('Angle')
grid on
function edit1_Callback(edit1, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
N=str2double(get(edit1,'string'));
assignin('base','N',str2double(get(edit1,'string')));
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(edit1, eventdata, handles)
% hObject handle to edit1 (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(edit1,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(edit1,'BackgroundColor','white');
end
function edit2_Callback(edit2, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
time=str2double(get(edit2,'string'));
assignin('base','time',str2double(get(edit2,'string')));
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(edit2, eventdata, handles)
% hObject handle to edit2 (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(edit2,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(edit2,'BackgroundColor','white');
end
So this undefined operator error keeps showing up:
Undefined operator ':' for input arguments of type 'struct'.
Error in CEN320Project>pushbutton1_Callback (line 97)
for k=1:N
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in CEN320Project (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)CEN320Project('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
if I get rid of the colon ":" then it says undefined operator "/", so I guess I have a bunch of "undefined operators" for struct type input arguments whatever that means. and if there is no calculations at all it says error using plot, not enough input arguments, How do I get the pushbutton to carry out these calculations and plots.
2 Comments
Stephen23
on 3 Dec 2019
Edited: Stephen23
on 3 Dec 2019
The variable N is a copy of the structure handles:
function pushbutton1_Callback(hObject, eventdata, handles)
...
guidata(hObject,handles)
N=guidata(hObject)
...
for k=1:N;
So your code is basically equivalent to:
function pushbutton1_Callback(hObject, eventdata, handles)
...
N=handles
...
for k=1:N;
What do you expect the colon operator to do with a structure?
Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!