Undefined function or variable

1 次查看(过去 30 天)
Yasyas9
Yasyas9 2020-6-26
评论: Yasyas9 2020-6-26
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 个评论

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parametric Spectral Estimation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by