Borrar filtros
Borrar filtros

matrix value propagation along the rows

2 visualizaciones (últimos 30 días)
Sanatjon Gofurov
Sanatjon Gofurov el 5 de Nov. de 2023
Comentada: Sanatjon Gofurov el 8 de Nov. de 2023
Hello,
A(1,1:7) vector and I want a mtrix where A is repeated in B matrix 19 rows B(1:19,1:7).
Matlab sims to have issues with B(1:19,:)=A, or B(1:19,1:7)=A.
So idea is A = [1 2 3 4 5 6 7]
and resulting
B = [
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
...
] (in 19 rows)
BR
Sanat

Respuesta aceptada

Bruno Luong
Bruno Luong el 5 de Nov. de 2023
Editada: Bruno Luong el 5 de Nov. de 2023
Any of these should do
A = [1 2 3 4 5 6 7]
A = 1×7
1 2 3 4 5 6 7
B(1:19,1:7)=repmat(A,19,1)
B = 19×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
B(1:19,1:7)=repelem(A,19,1)
B = 19×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
B(1:19,1:7)=A(ones(1,19),:)
B = 19×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
for r=1:19
B(r,:) = A;
end
B
B = 19×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

Más respuestas (1)

Atsushi Ueno
Atsushi Ueno el 5 de Nov. de 2023
A = [1 2 3 4 5 6 7];
B = repmat(A,[19,1])
B = 19×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

Categorías

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

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by