How can i start a matlab for loop variable with 001 instead of 1?

40 次查看(过去 30 天)
How can i start a matlab for loop variable with 001 instead of 1?
  4 个评论
geoabidali
geoabidali 2015-10-17
编辑:Walter Roberson 2015-10-17
close all
clear variables
clc
tic;
cd E:\Processing\Matlab_recent
% cd E:\Processing\amptest
k=0;
% ad=0;
for m=01:365;
mm=num2str(m);
if m < 10
mm1=strcat('00',mm);
elseif m < 100
mm1=strcat('0',mm);
else
mm1=strcat(mm);
end
cd(mm1)
direct = dir;
direct_len = length(direct);
% amps=0;
for i= 3:direct_len
name=getfield(direct(i),'name');
load(name);
len=length(name);
if len==15
a=str2num(name([5 6]));
b=name(11);
% else
% a=str2num(name([5]));
% b=name(10);
end
% psum=0;
ad=0;
if a==00 && b == 'Z'
k=k+1;
sta=m+2*(m-1);
x=data_hr;
x=data_hr*4.21398E+19; % counts(=normlcons*convfac) to true ground motion
x2=x.^2; % power of each signal
p=sum(x2);
hout(k,sta)=m;
hout(k,sta+1)=a;
hout(k,sta+2)=3;
hout_p_00(k,m)=p;
% total power of the signal
% hout(k,sta+3)=str2cat(name);
% hout(k,1)=m;
% hout(k,2)=a;
% hout(k,3)=3;
% psum=p+psum;
end
clear ('x','x2','p')
% p=0;
end
cd ..
[r c]= size(hout_p_00);
for f=1:r
ad = ad+hout_p_00(f,m);
end
% if psum==0
dout(m,1)=ad;
% else
% dout(m,1)=psum;
k=0;
end
% clear ('x','x2','p')
% k=0;
% end
toc;
geoabidali
geoabidali 2015-10-17
I am sorry to say that very beginner to matlab. Your kind help would be highly appreciated !

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2015-10-17
sprintf('%03d', SomeNumericValue)

更多回答(0 个)

类别

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