Partition a Big Matrix Into Pieces According to Values from A Vector
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alessandro
el 4 de Mzo. de 2014
Comentada: Alessandro
el 4 de Mzo. de 2014
I have a big matrix (approx 2000x2000 size). Based on another boolean vector (which is 2000x1), i want to remove rows or columns from a copy of the original big matrix, wether the i-th element of the vector is equal to 0 or not. By using the following code:
if true
A = rand(2000); % Generate Random Matrix
b = zeros(2000,1); % Initialize Vector
for l=1:size(b,1)
c = rand(1);
if c>0.5;
b(l,1) = 1; % Just Putting Random 1's in the Vector
end
row_id = find(Boun); % Create a Vector Containing the Indices of Rows/Columns to Eliminate
A_copy = A; % Copy of the Original Matrix
counter = 0; % Create a Counter
for m=1:size(row_id,1);
A_copy(row_id(m)-counter,:) = []; % Eliminate row
A_copy(:,row_id(m)-counter,:) = []; % Eliminate column
counter = counter +1
end
end
The efficiency of the method is very poor. I know that messing around with matrices dimensions is not a good idea. Any suggestions?
Thanks in advance.
0 comentarios
Respuesta aceptada
the cyclist
el 4 de Mzo. de 2014
Instead of the for loop, you can do
A_copy(row_id,:) = []; % Eliminate rows
A_copy(:,row_id) = []; % Eliminate columns
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!