How to reassign values to new array without using a loop

조회 수: 1 (최근 30일)
Master Yoda
Master Yoda 2021년 2월 24일
댓글: Master Yoda 2021년 2월 24일
I am trying to reassign values to a new matrix as a method of cleaning up / bookeeping / decreasing memory. My current code is as follows.
for i = 1:N,
newMat(i,:) = oldMat(dataVec1 == dataVec2(i), :);
end
This loop takes FOREVER to do as N is very large and length(dataVec1) > N. Is there a way to avoid a for loop to achieve this? I have tried using bsxfun, but the intermediate matrix far exceeds memory.

채택된 답변

David Hill
David Hill 2021년 2월 24일
[~,idx]=ismember(dataVec2,dataVec1);
newMat=oldMat(idx,:);

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by