Undefined function or variable

I tried the CSP program from this file exchange : https://www.mathworks.com/matlabcentral/fileexchange/22915-common-spatial-patterns but whenever i try the CSP function which is this one:
% CSP Function
% Coded by James Ethridge and William Weaver
function [result] = CSP3(varargin)
if (nargin ~= 2)
disp('Must have 2 classes for CSP!')
end
Rsum=0;
%finding the covariance of each class and composite covariance
for i = 1:nargin
%mean here?
R{i} = ((varargin{i}*varargin{i}')/trace(varargin{i}*varargin{i}'));%instantiate me before the loop!
%Ramoser equation (2)
Rsum=Rsum+R{i};
end
% Find Eigenvalues and Eigenvectors of RC
% Sort eigenvalues in descending order
[EVecsum,EValsum] = eig(Rsum);
[EValsum,ind] = sort(diag(EValsum),'descend');
EVecsum = EVecsum(:,ind);
% Find Whitening Transformation Matrix - Ramoser Equation (3)
W = sqrt(inv(diag(EValsum))) * EVecsum';
for k = 1:nargin
S{k} = W * R{k} * W'; % Whiten Data Using Whiting Transform - Ramoser Equation (4)
end
% Ramoser equation (5)
% [U{1},Psi{1}] = eig(S{1});
% [U{2},Psi{2}] = eig(S{2});
%generalized eigenvectors/values
[B,D] = eig(S{1},S{2});
% Simultanous diagonalization
% Should be equivalent to [B,D]=eig(S{1});
%%%%%verify algorithim
%disp('test1:Psi{1}+Psi{2}=I')
%Psi{1}+Psi{2}
%%%%%sort ascending by default
%[Psi{1},ind] = sort(diag(Psi{1})); U{1} = U{1}(:,ind);
%[Psi{2},ind] = sort(diag(Psi{2})); U{2} = U{2}(:,ind);
[D,ind]=sort(diag(D));B=B(:,ind);
%Resulting Projection Matrix-these are the spatial filter coefficients
result = B'*W;
end
it keeps giving me this error:
>> CSP3
Must have 2 classes for CSP!
Warning: Matrix is singular to working precision.
> In CSP3 (line 27)
Undefined function or variable 'S'.
Error in CSP3 (line 42)
[B,D] = eig(S{1},S{2});
or else if there's any other useful CSP file i'll be very grateful, thank you.

댓글 수: 5

KSSV
KSSV 2020년 6월 26일
What input you tried?
Yasyas9
Yasyas9 2020년 6월 26일
My inputs are going to be signals
meghannmarie
meghannmarie 2020년 6월 26일
Are you giving it any inputs? If I do not give the funtion any inputs it gives me that error:
CSP3()
If I put numbers in it works:
CSP3(1,2)
Yasyas9
Yasyas9 2020년 6월 26일
thank you meghannmarie
Yasyas9
Yasyas9 2020년 6월 26일
that was helpful

댓글을 달려면 로그인하십시오.

답변 (0개)

질문:

2020년 6월 26일

댓글:

2020년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by