How can I extract entries from a matrix and a vector into a new vector in a specific way?

1 vue (au cours des 30 derniers jours)
Hello, I want to extract the entries of a matrix and a vector into a new vector, like this:
M =
0.6000 0.8000
-0.8000 0.6000
t =
0.4000
0.8000
into this vector: v =
0.6000
0.8000
-0.8000
0.6000
0.4000
0.8000
How can I do it? and I would like to know how to do it the other way, like this: if v is given and I want to construct M and t from that v.
Thank you for your help!!

Réponse acceptée

Stephen23
Stephen23 le 25 Nov 2017
To get the correct order:
>> [reshape(M.',[],1);t(:)]
ans =
0.60000
0.80000
-0.80000
0.60000
0.40000
0.80000
  2 commentaires
Saf el
Saf el le 25 Nov 2017
Its working, thanks So if I want to do it the other way. I mean to get M and t from the given vector v. How to do it?
Stephen23
Stephen23 le 25 Nov 2017
>> V = [reshape(M.',[],1);t(:)];
>> reshape(V(1:4),2,2).'
ans =
0.60000 0.80000
-0.80000 0.60000
>> V(5:6)
ans =
0.40000
0.80000
>>

Connectez-vous pour commenter.

Plus de réponses (1)

mounika
mounika le 25 Nov 2017
M = [0.6,0.8;-0.8,0.6]
t = [0.4;0.8]
M = reshape(M,4,1)
v = vertcat(M,t)
Otherway:
M = v(1:4,:);
M = reshape(M,2,2);
t = v(5:6,;);
  2 commentaires
Saf el
Saf el le 25 Nov 2017
Modifié(e) : Saf el le 25 Nov 2017
Thank you for your help, but I need to have v like this: v =
0.6000
0.8000
-0.8000
0.6000
0.4000
0.8000
not this: v =
0.6000
-0.8000
0.8000
0.6000
0.4000
0.8000

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by