How to delete multiple row and column in matrix A and Delete row and column specified in matrix B?????????????/
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
A =[
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7];
size(A)= 18 * 7
B=[2;3;4;5;7;9;]
size(B)= 6 * 1
The deleted row and column specified in matrix B........
I want to delete in A matrix ........
B(1)=2 ie 2 row and 2 column delete in matrix A
B(2)=3 ie 3 row and 3 column delete in matrix A
B(3)=4 ie 4 row and 4 column delete in matrix A
and so on............
1 comentario
Rik
el 12 de Ag. de 2018
You can't delete single elements in arrays. You could replace them by NaN, but as you didn't explain what you want to do, I don't know if that would fit your needs.
Respuestas (1)
dpb
el 12 de Ag. de 2018
Editada: dpb
el 12 de Ag. de 2018
On the assumption it really is to remove the full row/column, not the individual element, "Dead ahead" is sometimes the simplest...
B=sort(B,'descend'); % will need to remove rows/columns from back going forward
for i=1:length(B)
A(B(i),:)=[]; % remove row
A(:,B(i))=[]; % remove column
end
NB: Your example above will fail as B(end)>size(A,2)
If the intent is to remove the row even if there isn't such a column, then incorporate error testing or just use a try...catch block to skip the addressing error.
for i=1:length(B)
try, A(B(i),:)=[]; catch,end % remove row if extant, don't error
try, A(:,B(i))=[]; catch,end % ditto remove column
end
0 comentarios
Ver también
Categorías
Más información sobre Multidimensional 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!