I have a matrix A = [1 1 0 0 1 1]

9 visualizaciones (últimos 30 días)
Hamza Naeem
Hamza Naeem el 8 de Feb. de 2020
Respondida: Stephen23 el 9 de Feb. de 2020
I have a matrix A = [1 1 0 0 1 1]. I want to add 0 one by one on this matrix like this
A = [0 1 1 0 0 1 1]
A= [1 0 1 0 0 1 1]
A = [1 1 0 0 0 1 1]
up to so on all the places. How I will do that via coding?

Respuestas (2)

KSSV
KSSV el 8 de Feb. de 2020
Editada: KSSV el 8 de Feb. de 2020
A = [1 1 0 0 1 1] ;
m = length(A) ;
B = zeros(m+1) ;
insert = @(a, x, n)cat(2, x(1:n), a, x(n+1:end));
for i = 1:m+1
T = insert(0,A,i-1) ;
B(i,:) = T ;
endfor

Stephen23
Stephen23 el 9 de Feb. de 2020
>> A = [1,1,0,0,1,1];
>> B = toeplitz([0,A])
B =
0 1 1 0 0 1 1
1 0 1 1 0 0 1
1 1 0 1 1 0 0
0 1 1 0 1 1 0
0 0 1 1 0 1 1
1 0 0 1 1 0 1
1 1 0 0 1 1 0

Categorías

Más información sobre Model Predictive Control Toolbox 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