I want to compare the utilityD for every iteration if the new utiltiyD is greater that old one old UtilityD then the old UtilityD with corresponding A1,D1,P will be deleted and new UtiltyD with the corresponding A1,D1,P values will replace the old one. Can someone help me to incorporate the above-mentioned requirement in the below-mentioned code?
A= rand(221);
resultD=zeros(221,4,10);
for i=1:10
A1= 0 + (1-0).*rand(221,1);
X11= A*A1;
P= zeros(221,1);
P(:)= X11(:)/max(X11);
D1= 0 + (1-0).*rand(221,1);
UtilityD=0;
for j=1:221
UtilityD= (((1-P(j))*(D(j)/(D(j)+A1(j)))* V)-C) +UtilityD;
end
resultD(:,1,i)=A1;
resultD(:,2,i)=D1;
resultD(:,3,i)=P;
resultD(1,4,i)=UtilityD;