Concatenate a matrix by rows problem
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
KSSV
am 2 Nov. 2016
Bearbeitet: KSSV
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!