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

44 ビュー (過去 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 件のコメント
Amar Kumar
Amar Kumar 2019 年 3 月 20 日
Thanks!
james
james 2020 年 11 月 25 日
Excellent

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by