필터 지우기
필터 지우기

Matrix operations that preserve floating point precision

조회 수: 1 (최근 30일)
Tolulope
Tolulope 2012년 8월 31일
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

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 8월 31일
편집: Sean de Wolski 2012년 8월 31일
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
Tolulope
Tolulope 2012년 8월 31일
Yep I have got the Stat Toolkit, so the dataset function works a treat. Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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