Index exceeds matrix dimensions.
2 views (last 30 days)
Show older comments
venkat sai gollapudi
on 23 May 2015
Answered: Walter Roberson
on 23 May 2015
Error in the command window
li=X1(clsi,:);
This how the program looks
function [W ,B]=scattermat(X1,y1)
%FUNCTION THAT CALCULATES SCATTER MATRIX:
% B:BETWEEN CLASS SCATTER MATRIX
% W:WITHIN CLASS SCATTER MATRIX
%
[~, l]=size(X1); %CALCULATE SIZE OF DATA
clases=unique(y1); %GET VECTOR OF CLASSES
total_clases=length(clases); %HOW MANY CLASSES
B=zeros(l,l); %INIT B AND W
W=zeros(l,l);
ovrmean=mean(X1); %MEAN OVER ALL DATA
for i=1:total_clases
clsi = find(y1==clases(i)); %GET DATA FOR EACH CLASS
display(clsi);
li=X1(clsi,:);
mclsi=mean(li); %MEAN PER CLASS
li=li-repmat(mclsi,length(clsi),1); %Xi-MeanXi
B=B+li'*li; %CALCULATE B
W=W+length(clsi)*(mclsi-ovrmean)'*(mclsi-ovrmean); %CALCULATE W
end
end
How do I resolve this issue ??? I am new to matlab. Please help me out.
0 Comments
Accepted Answer
Walter Roberson
on 23 May 2015
That could happen if the input vector y1 is not the same length as the number of rows in the input X1.
0 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!