MATLAB: If I use the following function to obtain scatter matrices then how could I pass the input data to this function ,please help me if anybody know?

amit nambair

function [B W]=scattermat(data,Y)
%FUNCTION THAT CALCULATES SCATTER MATRIX:
% B:BETWEEN CLASS SCATTER MATRIX
% W:WITHIN CLASS SCATTER MATRIX
%
[~, l]=size(data); %CALCULATE SIZE OF DATA
clases=unique(Y); %GET VECTOR OF CLASSES
tot_clases=length(clases); %HOW MANY CLASSES
B=zeros(l,l); %INIT B AND W
W=zeros(l,l);
overallmean=mean(data); %MEAN OVER ALL DATA
for i=1:tot_clases
clasei = find(Y==clases(i)); %GET DATA FOR EACH CLASS
xi=data(clasei,:);
mci=mean(xi); %MEAN PER CLASS
xi=xi-repmat(mci,length(clasei),1); %Xi-MeanXi
W=W+xi'*xi; %CALCULATE W
B=B+length(clasei)*(mci-overallmean)'*(mci-overallmean); %CALCULATE B
end
end

Best Answer

The first input needs to be a 2D array with one sample per row. The second input needs to be a numeric vector of class numbers, one entry for each row.
(The second input could also be a character vector, one character for each row, or a categorical array. It could also be a vector of string objects, one for each row. But it cannot be a cell array of strings.)