필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
kurdistan mohsin
kurdistan mohsin 2022년 6월 20일
편집: Jon 2022년 6월 20일
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
Jon
Jon 2022년 6월 20일
편집: Jon 2022년 6월 20일
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.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by