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

49 visualizaciones (últimos 30 días)
How can i start a matlab for loop variable with 001 instead of 1?
  4 comentarios
geoabidali
geoabidali el 17 de Oct. de 2015
Editada: Walter Roberson el 17 de Oct. de 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 el 17 de Oct. de 2015
I am sorry to say that very beginner to matlab. Your kind help would be highly appreciated !

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Oct. de 2015
sprintf('%03d', SomeNumericValue)
  3 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by