concatenate different data type matrices

I want to concatenate the following two matrix one matrix is (mxn) that has integer values and another matrix is (nx1) that has double values. I want to join (nx1) in the end of first matrix i.e. mxn. How can I do this. I tried using the following code
MATRIX =
5 4 3 3 3
2 3 3 5 4
4 2 5 3 2
5 5 3 4 3
MQtranspose =
0.6154
0.2222
0
0.8889
if true
rMATRIX = CAT(2,MATRIX,MQtranspose)
end
but its giving me error "Undefined function 'CAT' for input arguments of type 'double' ".

 採用された回答

Fangjun Jiang
Fangjun Jiang 2016 年 3 月 17 日
編集済み: Fangjun Jiang 2016 年 3 月 17 日

0 投票

lower case, cat(), not CAT().

2 件のコメント

Nida
Nida 2016 年 3 月 17 日
Thanks. This worked! BUT again the output is
rMATRIX =
3.0000 2.0000 4.0000 4.0000 2.0000 0
1.0000 2.0000 2.0000 3.0000 3.0000 0.6667
1.0000 2.0000 5.0000 1.0000 5.0000 0.4444
4.0000 3.0000 3.0000 2.0000 3.0000 0.4286
I do not want to convert the integers values to double. only last column should be double not the whole matrix
Fangjun Jiang
Fangjun Jiang 2016 年 3 月 17 日
That is going to be a problem. All the data in one matrix must be the same data type. Cell array can contain different types but that may not be what you want. The default data type for MATLAB numerical is double. You rMATRIX data seems to be double data type although it looks like integer. Take a look at the following example:
>> a=magic(3);b=rand(3,1);
>> cat(2,a,b)
ans =
8.0000 1.0000 6.0000 0.1576
3.0000 5.0000 7.0000 0.9706
4.0000 9.0000 2.0000 0.9572
>> a=uint8(magic(3));
>> cat(2,a,b)
ans =
8 1 6 0
3 5 7 1
4 9 2 1

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2016 年 3 月 17 日

コメント済み:

2016 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by