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??

2 次查看(过去 30 天)
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
  3 个评论
Sayed Afreen
Sayed Afreen 2017-7-6
I am not using this code as it is ,I just want to clear my doubt which I have explain above.please dont mine but I already done with my own code ,I thought that if I ask the question on this code then may be my error will be removed because my code related somewhat to above code.Thanks!!
Jan
Jan 2017-7-6
@Sayed: Okay. I really like well documented code, which explains the inputs, actions and the output exhaustively with the obvious intention to make it as easy and trustworthy as possible to use the code. This does not help only other, but the author also after some month, when the exact intention of the code has been forgotton. Note that the code lines itself are well documented. Only the meaning of the inputs have been forgotten.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-7-6
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.)
  4 个评论
Walter Roberson
Walter Roberson 2017-7-7
y1 = [x1; x2; x3; x4; x5; x6];
cl1 = ones(size(y1));
y2 = [x7; x8; x9; x10; x11; x12];
cl2 = 2 * ones(size(y2));
data = [y1;y2];
data_class = [cl1; cl2];
scattermat(data, data_class)
Ameer Hamza
Ameer Hamza 2018-11-6
How can i pass the data when i have 3 classes w1, w2 and w3 with three feature vectors each i.e x1,x2,x3 and each feature vector has 10 samples ? Guide please

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by