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

조회 수: 10 (최근 30일)
geoabidali
geoabidali 2015년 10월 17일
댓글: james 2020년 11월 25일
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)
  댓글 수: 3

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by