MATLAB Answers

How to reassign values to new array without using a loop

29 views (last 30 days)
Master Yoda
Master Yoda on 24 Feb 2021
Commented: Master Yoda on 24 Feb 2021
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), :);
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.

Accepted Answer

David Hill
David Hill on 24 Feb 2021

More Answers (0)




Community Treasure Hunt

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

Start Hunting!