Clear Filters
Clear Filters

Undefined function or variable

7 views (last 30 days)
Yasyas9
Yasyas9 on 26 Jun 2020
Commented: Yasyas9 on 26 Jun 2020
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 Comments
Yasyas9
Yasyas9 on 26 Jun 2020
thank you meghannmarie
Yasyas9
Yasyas9 on 26 Jun 2020
that was helpful

Sign in to comment.

Answers (0)

Categories

Find more on Eigenvalues & Eigenvectors 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!