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
lower case, cat(), not CAT().

2 个评论

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
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 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