Help me for simplify this program



Hi,

I have program for showing strong of event here. In this data we have 13 anomaly event based on data(:,3)>4.4 from my data.

In this program (below) for instance, I just do for 4 anomaly data (event 1, event 2, event 3, event 4), and if you want, actually through to 13 event.

So, can any body help me, how to simplify this program using FOR, starting from event 1 and event 4. The last program is collecting the data every event and response. If I do, until event 13 by copy, the program is not effective. How do if I have 500 event? So, very hard to collected.

Thank very much for help and appreciation.

Kate

% Program look effect of parameter based event anomaly
% Test my data
data=[[ones(31,1); ones(28,1)*2; ones(31,1)*3; ones(10,1)*4] ...
[(1:31)'; (1:28)'; (1:31)'; (1:10)'] rand(100,1)*5 rand(100,1)*25];

num=3; % extracting data before and after anomaly event
X=find(data(:,3)>4.4); A=data(X,[1:4]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% event 1
x1=find(data(:,1)==A(1,1) & data(:,2)==A(1,2));
y1=data(x1,[3:4]);

% extracting data before and after data and respon
event1 = [data(x1-num:x1-1,3); y1(1); data(x1+1:(x1+1+num-1),3)];
respon1= [data(x1-num:x1-1,4); y1(2); data(x1+1:(x1+1+num-1),4)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% event 2
x2=find(data(:,1)==A(2,1) & data(:,2)==A(2,2));
y2=data(x2,[3:4]);

% extracting data before and after data and respon
event2 = [data(x2-num:x2-1,3); y2(1); data(x2+1:(x2+1+num-1),3)];
respon2= [data(x2-num:x2-1,4); y2(2); data(x2+1:(x2+1+num-1),4)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% event 3
x3=find(data(:,1)==A(3,1) & data(:,2)==A(3,2));
y3=data(x3,[3:4]);

% extracting data before and after data and respon
event3 = [data(x3-num:x3-1,3); y3(1); data(x3+1:(x3+1+num-1),3)];
respon3= [data(x3-num:x3-1,4); y3(2); data(x3+1:(x3+1+num-1),4)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% event 4
x4=find(data(:,1)==data(4,1) & data(:,2)==data(4,2)); y4=data(x4,[3:4]);

% extracting data before and after data and respon
event4 = [data(x4-num:x4-1,3); y4(1); data(x4+1:(x4+1+num-1),3)];
respon4= [data(x4-num:x4-1,4); y4(2); data(x4+1:(x4+1+num-1),4)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% collecting for all event and response as follow:
tot_event = [event1'; event2'; event3'; event4'];
tot_respon=[respon1'; respon2'; respon3'; respon4'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
.