Filter löschen
Filter löschen

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 Ansichten (letzte 30 Tage)
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 Kommentare
Sayed Afreen
Sayed Afreen am 6 Jul. 2017
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 am 6 Jul. 2017
@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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 6 Jul. 2017
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 Kommentare
Walter Roberson
Walter Roberson am 7 Jul. 2017
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 am 6 Nov. 2018
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by