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 Center および File ExchangeFortran with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by