# Matrix operations that preserve floating point precision

5 visualizaciones (últimos 30 días)
Tolulope el 31 de Ag. de 2012
When concatenating a matrix from the row element of a cell array, I find that the floating points are always converted to integers. How do avoid this?
E.g.
Q = {[1;2;3],[4.000;5.000;6.000],[7e+04;8e+03;9e+02],[0.1234;0.34;0.4]};
P = [Q{1}];
for i=2:4
P = cat(2,P,Q{i});
end
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuesta aceptada

Sean de Wolski el 31 de Ag. de 2012
Editada: Sean de Wolski el 31 de Ag. de 2012
The values will be converted to the most restrictive class so preconvert the integers to double:
Q = cellfun(@double,Q,'UniformOutput',0);
Also rather than the for-loop you can use the comma-separated list expansion of the cell array:
P = horzcat(Q{:});
Of course if you would like the best of both worlds (floats and integers) and would like to have them in a non-cell array (and you have the Statistics Toolbox) then you could use a dataset
Q = {uint8([1;2;3]),uint32([4.000;5.000;6.000]),[7e+04;8e+03;9e+02],[0.1234;0.34;0.4]};
D = dataset(Q{:})
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Tolulope el 31 de Ag. de 2012
Yep I have got the Stat Toolkit, so the dataset function works a treat. Thanks

Iniciar sesión para comentar.

### Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by