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' ".

 Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 17 de Mzo. de 2016
Editada: Fangjun Jiang el 17 de Mzo. de 2016

0 votos

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

2 comentarios

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 17 de Mzo. de 2016

Comentada:

el 17 de Mzo. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by