# how to use for loops command to ignore 10 times the same code?

2 views (last 30 days)
davit petraasya on 13 Sep 2016
Commented: davit petraasya on 19 Sep 2016
Hi all
I am writing code and getting result. But my code is too long, I am just repeating the same code 10 times to get 10 curves and average of the 10 curves.
Is there any way to make shorter my code?
Thanks a lot!
##### 2 CommentsShowHide 1 older comment
davit petraasya on 19 Sep 2016
Thanks Stephen for the full answer!

Andrei Bobrov on 13 Sep 2016
Edited: Andrei Bobrov on 13 Sep 2016
x= NUMERIC(:,1);
y = NUMERIC(:,2);
Mag = NUMERIC(:,3);
date_num = datenum(TXT,'dd.mm.yy');
date1=datenum('01/01/1962','dd/mm/yyyy');
date2=datenum('01/01/2016','dd/mm/yyyy');
A=-0.59;
B=43.45;
L=0.09;
x11=A-L;
x22=A+L;
y11=B-L;
y22=B+L;
t = x > x11 & x < x22 & y > y11 & y < y22 &...
date_num > date1 & date_num < date2;
s = [numel(Mag),10];
[~,ii] = sort(rand(s));
Mag1 = Mag(ii);
condition = bsxfun(@and,Mag1 >= 2.5, t);
Distance = datenum(1960+(0:3:18*3)',7,1);
b = histc(bsxfun(@times,date_num,condition),Distance);
plot(Distance,b,'r','LineWidth',1);
##### 2 CommentsShowHide 1 older comment
davit petraasya on 19 Sep 2016
Thank you very much Andrei, good job!