How to convert a 'char' into 'double' data type without disrupting the data?

조회 수: 3 (최근 30일)
Afaq Ahmad
Afaq Ahmad 2021년 1월 21일
댓글: Afaq Ahmad 2021년 1월 22일
I am working on an image which I have converted into its bits having a size of 1*2000001 and of "char" data type. I need to use interp() to interpolate it by a factor of 3 making it 1*6000001. I have converted it into 'double' data type by the following:
Interp() accepts only ‘double’ data types. I need to further process the bits in ‘char’. But at this point, all the values have been corrupted, meaning that now, the bits are useless. I am confused here, what the exact problem is?In simple words, I have an array of 1*2000001 ‘char’ which I need to interpolate by 3. But it seems that the conversion from ‘char’ to ‘double’ and vice versa is corrupting the data bits making it useless.

답변 (1개)

Steven Lord
Steven Lord 2021년 1월 21일
You could try adding back in the '0' that you subtracted to create DoubleC from C, but keep in mind that not all the values in InterpolatedC are likely to be integer values.
C = char('0'+pi)
C = '3'
If you want a text representation of a number you might find string, num2str, sprintf, etc. better choices.
S1 = string(pi)
S1 = "3.1416"
S2 = num2str(pi)
S2 = '3.1416'
S3 = sprintf('%1.9f', pi)
S3 = '3.141592654'
  댓글 수: 1
Afaq Ahmad
Afaq Ahmad 2021년 1월 22일
Yes I tried adding it back to '0' as well. It does convert the data type back into char, but the values are becoming corrupted. It appears to me that this type of conversion is not suitable. Char is being converted into double and vice versa, but the data is causing the trouble.

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

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by