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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by