MATLAB: How to store value for multiple iteration

MATLAB

a= 10;
b= [1 0 0 0 1 0 1 0 1 0;1 1 0 0 1 0 1 0 1 1;1 0 1 0 1 0 1 1 1 0;1 1 1 1 1 0 1 0 1 0;1 0 1 0 1 0 1 0 1 0 ];
e= [0.05 0.08 0.2 0.4];
iteration= 1;
x= zeros(1,1);
g= eye(10);
G= [g;b];
for t=1 : iteration
s=zeros(4,1);
offset=1;
for u=e(1:length(e))
F = G ;
for i=1:15
if(rand < u)
F(i,:) = 0;
end
end
soup=zeros(1,a);
for k = 1 : 15
FD = max( F(k,:)-soup, 0) ;
if( sum(FD) == 1)
[MaxValue Idx] = max(FD) ;
soup(Idx) = 1 ;
end
end
h =sum(soup) ;
s(offset,:)=h;
offset=offset+1;
end
end
Now I want to change the value of “iteration” and want to make it 1000; For, each “iteration”
I want to count how many values of “s” are equal to “a”. Suppose, for each “iteration” the number of values in “s” that are equal to “a” is “T”(Let) Then I want to divide “T” by length(e) for each iteration. Suppose that value for each iteration is V (Let) Then I want to get the average value of V for total thousand “iteration” Example: Let, for 2 iteration, the number of values in “s” that are equal to “a” is 3,2 So,
For iteration=1, V=3/length(e)=3/4=0.75
For iteration = 2, V=2/length(e)=0.5
So, average value of V for two iteration = (0.75+0.5) / 2 = 0.625
I tried for several times but unable to do so.
Matlab experts please need your help and suggestion.

Best Answer

a= 10;
b= [1 0 0 0 1 0 1 0 1 0;1 1 0 0 1 0 1 0 1 1;1 0 1 0 1 0 1 1 1 0;1 1 1 1 1 0 1 0 1 0;1 0 1 0 1 0 1 0 1 0 ];
e= [0.05 0.08 0.2 0.4];
iteration= 1000;
x= zeros(1,1);
g= eye(10);
G= [g;b];
V=zeros(1,iteration);
for t=1 : iteration
s=zeros(4,1);
offset=1;
for u=e(1:length(e))
F = G ;
for i=1:15
if(rand < u)
F(i,:) = 0;
end
end
soup=zeros(1,a);
for k = 1 : 15
FD = max( F(k,:)-soup, 0) ;
if( sum(FD) == 1)
[MaxValue Idx] = max(FD) ;
soup(Idx) = 1 ;
end
end
h =sum(soup) ;
s(offset,:)=h;
offset=offset+1;
end
T=sum(s==a);
V(t)=T/length(e);
end
avgV=mean(V)