str2double('00010001') or str2num('00010001') gives output as 10001 by ignoring the MSB '000' bits how to retain them?

조회 수: 4 (최근 30일)
Hi, I have some filenames which start with '0**' something like that (00010001,00010002,...00010010 etc), When I use str2double on that filename string str2double('00010001') it outputs 10001 without considering the MSB bits. Is there anyway I can get the filename as '00010001'?
Thanks, Gopi
  댓글 수: 2
KSSV
KSSV 2017년 3월 14일
As it is a file name it's class will be char/ string. Why to use str2double?
Gopichandh Danala
Gopichandh Danala 2017년 3월 14일
The problem is lets say the filenames are '1','2','10' and I want to read them in order after reading files Matlab by default reads them in order of '1','10' and then '2'. Even if i use sort function it does the same. So I need to get all filenames ans sort them properly before reading them

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

답변 (1개)

Akira Agata
Akira Agata 2017년 3월 14일
I think you want to generate a list of file names with serial number whose prefix is '0001'. If so, the following code will help. This generates the file name list from '00010001' with length of N.
N = 10;
list = strcat(repmat('0001',N,1),num2str((1:N)','%04d'));
  댓글 수: 3

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by