Effacer les filtres
Effacer les filtres

how to repeat the while loop with the same value of matrix

2 vues (au cours des 30 derniers jours)
kurdistan mohsin
kurdistan mohsin le 20 Juin 2022
Modifié(e) : Jon le 20 Juin 2022
hello, i have the bellow code , for the second while loop this will be excuted untill matrix L is empty , but i want to repeat the excution for 10 times, so i put the first while loop for iteration, at the end of each iteration of 2nd while loop when the value of L is equal to zero it will make L=L1, where i store the values of L in L1 before excution so i can use it again , at each iteration it will give me different maxRwrd so it will compare it with the previous iteration at the end it will give the maximum one of all iteration , can anyone correct the code for me please ?
MAXRWRD = -Inf;
itermax = 10;
iter = 0;
while iter<itermax
iter=iter+1;
while sum(sum(L))>0
D = zeros(size(L));
for v = 1:N
idx = find(L(v,:)==1);
n = numel(idx);
if n ~= 0
in = randi(n);
D(v,idx(in)) = 1.0;
for m=1:M
for i=1:N
if D(v,m)==1 && c(v,i,m)==0
D(v,m)=1;
Rwr(v,m)=Rwrd(v,m);
L(v,m)=0;
elseif D(v,m)==1 && c(v,i,m)==1
D(v,m)=1;
L(i,m)=0;
Rwr(v,m)=Rwrd(v,m);
L(v,m)=0;
end
end
end
end
end
end
DD=D
REWARD=Rwr
MaxRwrd=sum(sum(Rwr))
MAXRWRD = max(MAXRWRD,MaxRwrd)
L=L1
end
MAXRWRD
AVGMAXRWRD=MAXRWRD/N
  1 commentaire
Jon
Jon le 20 Juin 2022
Modifié(e) : Jon le 20 Juin 2022
What errors are you getting? Please post the entire error message. In the code you have provided L, N and perhaps other variables are not defined, so I, and others who might respond, can't run the code to see what the problem is. Please provide a self contained example that reproduces the problem.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by