Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices 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