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

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에 대해 자세히 알아보기

질문:

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