Hi. I have 2 matrices A(24,1) and B(24,1), and i want to create the matrix C(24,144), using the elements of A and B as follows (you can use lower triangular matrix and the For loop):
Thanks

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 18 de Mayo de 2016

0 votos

A=1:24;
B=A*10;
C=zeros(24,144);
p=0;
for k=1:6:144
p=p+1;
C(p:end,k)=A(p);
C(p:end,k+1)=B(p);
end
C

Más respuestas (1)

Roger Stafford
Roger Stafford el 18 de Mayo de 2016

1 voto

C = zeros(24,144);
C(:,1:6:end) = tril(repmat(A.,24,1));
C(:,2:6:end) = tril(repmat(B.,24,1));

2 comentarios

ET-TAOUSSI mehdi
ET-TAOUSSI mehdi el 18 de Mayo de 2016
it does not work. check syntax.
Roger Stafford
Roger Stafford el 18 de Mayo de 2016
Editada: Roger Stafford el 18 de Mayo de 2016
It works on my machine! You better check it again. Also remember that you stated A and B were to be 24-element column vectors, not row vectors. If they are actually row vectors, just drop the transposition operators on A and B.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 18 de Mayo de 2016

Editada:

el 18 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by