How to find a decimal point value and to stop at the first value

1 visualizzazione (ultimi 30 giorni)
Hi there,
I am trying to make a script where I can define a variable as the number of vectors required to capture at least 99.9% of the variance.
I am trying to get the first output in 'test' that is 99.9 assigned to a variable. Also, the while loop isn't working as I intended, as the size(test) outputs 60 1. My intention for the while loop was to scan through test and stop once the limit (99.9) was found. My intention is If I could size(test), I could use a find feature to find the first 99.9 value.
Any help is appreciated.
Below is my script:
[eigvects,~,eigvals] = pca(D);
cumulative_percent_variance_permode = 100*eigvals/sum(eigvals);
test = cumsum(cumulative_percent_variance_permode)
limit = 99.9
while test < limit
i = 1:length(test);
if i(test) == limit
break
end
end
size(test)

Risposta accettata

Walter Roberson
Walter Roberson il 20 Gen 2021
[eigvects,~,eigvals] = pca(D);
cumulative_percent_variance_permode = 100*eigvals/sum(eigvals);
test = cumsum(cumulative_percent_variance_permode);
i = find(test >= limit, 1, 'first');

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by