Typecasting a matrix of 200x8 uint8 to double

조회 수: 15 (최근 30일)
vishwajit jadhav
vishwajit jadhav 2018년 9월 18일
댓글: Christopher Wallace 2018년 9월 18일
I am typecasting data from uint8 to double so I am using typecast function. I have matrix of 200x8 uint8 which want to convert it into double. So if I use a for loop like below.
if true
convert_double = [];
a = [200x8];
for i =1:200
convert_double = [convert_double; typecast(uint8(a(i,:)), 'double')];
end
end
But I want to remove this for loop so that in one instance itself I will get 200x1 double data

답변 (2개)

Guillaume
Guillaume 2018년 9월 18일
Transpose your a before reshaping into a vector:
convert_double = typecast(reshape(uint8(a'), 1, []), 'double')

Christopher Wallace
Christopher Wallace 2018년 9월 18일
  댓글 수: 2
Guillaume
Guillaume 2018년 9월 18일
편집: Guillaume 2018년 9월 18일
There is a big difference between plain conversion with double and casting with typecast. Compare
a = uint8([154, 8, 27, 158, 94, 41, 240, 63])
double(a)
typecast(a, 'double')
Christopher Wallace
Christopher Wallace 2018년 9월 18일
Absolutely, depends on what the author wants to do with the data. After seeing your answer I see what the "200x1 double data" portion was aiming at.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by