How to reassign values to new array without using a loop

1 visualización (últimos 30 días)
Master Yoda
Master Yoda el 24 de Feb. de 2021
Comentada: Master Yoda el 24 de Feb. de 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), :);
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.

Respuesta aceptada

David Hill
David Hill el 24 de Feb. de 2021
[~,idx]=ismember(dataVec2,dataVec1);
newMat=oldMat(idx,:);

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by