Variable for loop storage

2 visualizaciones (últimos 30 días)
Cside
Cside el 3 de Ag. de 2020
Respondida: madhan ravi el 3 de Ag. de 2020
Hi, I currently have this code which allows the for loop to run based off an array, but I cannot run the same for loop to create a new matrix (the size of the matrix should be the number of loops run). Is there a way I can code for this better? Thank you!
lowPs = 50 x 1 array [101,105,107....], variable pattern
A is a 170 x 50 matrix
for k = lowPs(1:end)
B = find(A(:,1) == k)); %%row numbers in A where A(:,1) that contain the integer in lowPs
low = A(B,:); %% extract these rows from A and build it into a new matrix low, low should be 50 x50
end

Respuesta aceptada

madhan ravi
madhan ravi el 3 de Ag. de 2020
low = cell(numel(lowPs), 1);
for k = 1 : numel(lowPs)
B = A(:,1) == lowPs(k); %%row numbers in A where A(:,1) that contain the integer in lowPs
low{k} = A(B, :); %%extract these rows from A and build it into a new matrix low, low should be 50 x50
end
low = cat(1, low{:});

Más respuestas (1)

madhan ravi
madhan ravi el 3 de Ag. de 2020
low = A(lowPs, :)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by