Hello,
I have two matrices for example A = [1; 2; 3; 4; 5] and B = [A; B; C; D; E]. I would like to combine them in such a way that I get C = [1; A; 2; B; 3; C; 4; D; 5; E].
Can you please help me with this task? Thank you so much ?

 Réponse acceptée

Stephan
Stephan le 4 Jan 2019
Modifié(e) : Stephan le 4 Jan 2019
Hi,
try:
A = [-1; -3; -5; -7; -9]
B = [2; 4; 6; 8; 10]
result = reshape(([A B])',[],1)
gives:
A =
-1
-3
-5
-7
-9
B =
2
4
6
8
10
result =
-1
2
-3
4
-5
6
-7
8
-9
10
or with symbolic variables:
syms a b c d e
A = [1; 2; 3; 4; 5];
B = [a; b; c; d; e];
result = reshape(([A B].'),[],1)
results in:
A =
1
2
3
4
5
B =
a
b
c
d
e
result =
1
a
2
b
3
c
4
d
5
e
Best regards
Stephan

1 commentaire

Ann
Ann le 5 Jan 2019
Thank you so much for this two examples of solving this problem! It works perfectly in my task :)
Kind regards
Ann

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by