So my problem was, when i'm trying to combine number from different columns, leading zeros disappear, here's my code:
Bthree= [0 0 1
9 1 2
0 5 7]
len=size(Bthree);
A=[];
for jj=1:len(1)
s=int2str(Bthree(jj,1:3));
s=s(s~=' ');
A(jj,:)=[str2num(s)];
end
Output
1
912
57
as you can see leading zeros disappear but i want zero to be keep
desired output:
001
912
057
so can i do that? thanks
If you want to keep leading zeros you likely need to store your data as strings:
Bcell = strrep(cellstr(num2str(Bthree)),' ','')
returns a cell array of strings our your numbers. For a char array additional do:
Bchar = cell2mat(Bcell)
Or alternatively you can get the char array directly by:
Bchar = reshape(sprintf('%i',Bthree),size(Bthree))
returning:
Bcell =
'001'
'912'
'057'
Bchar =
001
912
057
As you seem to be not sure if you really need the leading zeros, here a short way for the conversion to doubles:
Bdouble = str2num(Bchar)
Bdouble =
1
912
57
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다