Concatenate a matrix by rows problem

조회 수: 1 (최근 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