How can i add zeros to same specified matrix column and row?

1 visualización (últimos 30 días)
Hi there,
I want to change my array A(5x5) to adding zeros to 4th and 5th columns and rows. So, output of A matrix can be (7x7) matrix.
A=[1,2,3,4,5;
6,7,8,9,10;
11,12,13,14,15;
16,17,18,19,20;
21,22,23,24,25]
to
A = [1,2,3,0,0,4,5;
6,7,8,0,0,9,10;
11,12,13,0,0,14,15;
0,0,0,0,0,0,0;
0,0,0,0,0,0,0;
16,17,18,0,0,19,20;
21,22,23,0,0,24,25]

Respuesta aceptada

madhan ravi
madhan ravi el 30 de Mayo de 2020
[m,n] = size(A);
rc = [4,5]; % where to place zeros
N = 2; % 2 columns and rows
b = zeros(m+N,N+n);
R = setdiff(1:m+N,rc);
C = setdiff(1:n+N,rc);
b(R,C) = A % b is your new A

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by