optimize my matrix function

조회 수: 2 (최근 30일)
danielle sisserman
danielle sisserman 2020년 11월 7일
댓글: danielle sisserman 2020년 11월 7일
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

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 7일
knn_labels = reshape( classifier.YTrain(k_indices), [], 1);
  댓글 수: 1
danielle sisserman
danielle sisserman 2020년 11월 7일
perfect! thank you Walter :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by