Concatenate a matrix by rows problem

8 次查看(过去 30 天)
Ubaldo
Ubaldo 2016-11-2
编辑: KSSV 2016-11-2
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)?

回答(1 个)

KSSV
KSSV 2016-11-2
编辑:KSSV 2016-11-2
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

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by