Indexing problem. I want to insert a vector into another vector with a loop.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a matrix A, whose initial form is as follows:
A = [5 4 3]
By using the following expression:
A = [A,zeros(1, 12)];
My matrix turns into:
A = [5 4 3 0 0 0 0 0 0 0 0 0 0 0 0]
I want to insert a vector
i = [1 -1 -1 1]
, and create multiple expressions of A, via a loop.
The result should be something like this:
A = [5 4 3 1 -1 -1 1 0 0 0 0 0 0 0 0]
And then like this:
A = [5 4 3 0 0 1 -1 -1 1 0 0 0 0 0 0 ]
And later like this:
A = [5 4 3 0 0 0 0 1 -1 -1 1 0 0 0 0 ]
The final form of A, should be like this:
A = [5 4 3 0 0 0 0 0 0 0 0 1 -1 -1 1]
How could I code a loop that generates these versions of A?
0 comentarios
Respuestas (1)
the cyclist
el 22 de Jun. de 2020
Here is one way.
A = [5 4 3];
B = [1 -1 -1 1 0 0 0 0 0 0 0 0 0 0];
for nb = 0:numel(B)-4
output = [A circshift(B,nb)]
end
The variable output is the different "versions of A".
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing 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!