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

40 vues (au cours des 30 derniers jours)
geoabidali
geoabidali le 17 Oct 2015
Commenté : james le 25 Nov 2020
How can i start a matlab for loop variable with 001 instead of 1?
  4 commentaires
geoabidali
geoabidali le 17 Oct 2015
Modifié(e) : Walter Roberson le 17 Oct 2015
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 le 17 Oct 2015
I am sorry to say that very beginner to matlab. Your kind help would be highly appreciated !

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 17 Oct 2015
sprintf('%03d', SomeNumericValue)
  3 commentaires
Amar Kumar
Amar Kumar le 20 Mar 2019
Thanks!
james
james le 25 Nov 2020
Excellent

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by