Concatenate a matrix by rows problem
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello. I have noticed a strange behavior when concatenating matrix rows. For example, I have those two matrices:
H =
2.0417 0.0208 0.0000
0.0208 2.0200 0.0000
0.0000 0.0000 2.0000
F =
0.1233 0.0801 0.0001
0.4082 0.2002 0.0002
If I type HH = H(:)' I got
HH =
2.0417 0.0208 0.0000 0.0208 2.0200 0.0000 0.0000 0.0000 2.0000
which is correct, as I want to concatenate the matrix row in a long row. On the other hand, if I try FF = F(:)' I got
FF =
0.1233 0.4082 0.0801 0.2002 0.0001 0.0002
which is not correct as the columns are concatenated in a long row.
Is there a way to get always the same result (in my case row concatenation in a long row)?
0 commentaires
Réponses (1)
KSSV
le 2 Nov 2016
Modifié(e) : KSSV
le 2 Nov 2016
If A is any matrix, when you type A(:), it always concatenates column wise irrespective of it's dimensions. If you want to change it's behavior like you mentioned in my case row concatenation in a long row; you have to transpose the matrix and then use :.
F = [0.1233 0.0801 0.0001
0.4082 0.2002 0.0002] ;
F = F' ;
FF = F(:) ;
You put a if condition and proceed with transpose.
if size(F,1) < size(F,2)
F = F' ;
FF = F(:) ;
end
0 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!