How to store value for multiple iteration

조회 수: 2 (최근 30일)
Eagle
Eagle 2013년 10월 23일
댓글: A Jenkins 2013년 10월 23일
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.

채택된 답변

A Jenkins
A Jenkins 2013년 10월 23일
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)
  댓글 수: 2
Eagle
Eagle 2013년 10월 23일
편집: Eagle 2013년 10월 23일
@ A Jenkins- if s=[100 x 57] matrix then i cannot find the value of V. Please need your help.
A Jenkins
A Jenkins 2013년 10월 23일
편집: A Jenkins 2013년 10월 23일
sum() itself sums over one dimension. If you have a two dimensional matrix, you need to sum twice.
T=sum(sum(s==a))
Another option, if the dimensions of s can change:
T=sum(reshape(s,1,[])==a)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by