how to repeat the while loop with the same value of matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Jon
el 20 de Jun. de 2022
Editada: Jon
el 20 de Jun. de 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.
Respuestas (0)
Ver también
Categorías
Más información sobre Multidimensional Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!