optimize my matrix function

2 vues (au cours des 30 derniers jours)
danielle sisserman
danielle sisserman le 7 Nov 2020
this is my code:
t=1;
for j=k_indices
knn_labels(t,1) = classifier.Ytrain(j,1);
t = t+1;
end
what I'm doing here is using a vector of indices to create a vector of the values at those indices using some other matrix:
example:
But, I am sure that there is some pretty one liner that does this. Any one knows what that line looks like?
Thank you

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Nov 2020
knn_labels = reshape( classifier.YTrain(k_indices), [], 1);
  1 commentaire
danielle sisserman
danielle sisserman le 7 Nov 2020
perfect! thank you Walter :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by