필터 지우기
필터 지우기

why leading zeros are gets disappeared when i convert an character array to double matrix and can i convert the character array to binary matrix if yes then plz. suggest?

조회 수: 6 (최근 30일)
g=str2num(c); c is character array. why leading zeros are gets disappeared when i convert an character array to double matrix and can i convert the character array to binary matrix if yes then plz. suggest..
  댓글 수: 1
aditya kumar sahu
aditya kumar sahu 2016년 11월 10일
a=imread('f.jpg');
c=dec2bin(b); /*here c is a character array*\
d=num2cell(c);/*here d is a cell array*\
g=str2num(c);/*here g is a double array*\
we can see in g the binary values leading zeros are eliminated.this is my first doubt
again can i convert the character array 'c' to binary matrix.
Thank you

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

답변 (2개)

Guillaume
Guillaume 2016년 11월 10일
Because the numbers 001, 01, 1 are all the same (and so is 1 with an infinite numbers of leading 0), numbers are printed without leading zeros. It's the same way we normally write numbers.
Note that matlab has no concept of a binary number. For matlab the number 1001, is the decimal integer between 1000 and 1002, not the equivalent of decimal 9.
As I said before there are matlab functions to manipulate bits of numbers without having to convert them to string or decimal numbers posing as binary.
Also be aware that str2num is a very dangerous function, str2double is much safer. str2num will not just convert strings to numbers, it will also execute any instruction in the string (e.g. format the hard drive).
  댓글 수: 1
John D'Errico
John D'Errico 2016년 11월 10일
It is not even that numbers are printed without the leading zeros. The leading zeros are simply not stored when the number is converted to a double.

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


KSSV
KSSV 2016년 11월 10일
sprintf('%05d',5)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by