how to use for loops command to ignore 10 times the same code?
2 views (last 30 days)
Show older comments
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!
Accepted Answer
Andrei Bobrov
on 13 Sep 2016
Edited: Andrei Bobrov
on 13 Sep 2016
[NUMERIC,TXT]=xlsread('whole10L22.xlsx');
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);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!