Clear Filters
Clear Filters

How to find certain index of a diagonal matrix , when a condition meets?

1 view (last 30 days)
I have the following code:
covar = 1.0/m .* X' * X; % computing co-variance
[U, S, V] = svd(covar); % singular value decomposition % U contains principal components and V contains diagonal matrix
% %% % % ===== Dimensioanlity Reduction Finding K for projection======
s3=sum (diag(S));
sum1=0;
temp1=0;
for j=1:length(S)
sum1=sum1+S(j,j);
div_res=(sum1/s3);
if(div_res==0.9)
index=find(j) ;
end
end
All I want is, that value of "j" when the div_res=>0.9 but I am not getting the correct answer

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 25 Apr 2014
n=size(A,1);
idx=find(A(sub2ind([n n],1:n,1:n))>=0.9)

More Answers (0)

Categories

Find more on Operating on Diagonal 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!