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

1 次查看(过去 30 天)
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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by