# Storing information from a loop over 3 variables

조회 수: 2 (최근 30일)
RP 2022년 4월 4일
편집: Geoff Hayes 2022년 4월 4일
The code below seems to store the results from each loop as opposed to providing the results from the current loop.
So, for example Table(1,1,2) has the results of Table (1,1,1) and Table (1,1,2).
SCR=prctile(x,0.5);
rho=0;
muinputs=[-0.025,-0.010,0.0181,0.025];
sigmainputs=[0.0125,0.0287,0.0501,0.0751];
Table=cell(4,4,9);
for i=1:4
for j=1:4
for ii=1:9
muy=-muinputs(i)*SCR;
sigmay=-sigmainputs(j)*SCR;
%muy=-0.1*SCR;
%sigmay=-0.1*SCR;
y(:,ii)=Testlooping(x,rho,muy,sigmay);
y2(:,ii)=x+y(:,ii);
y3(:,ii)=prctile(y2(:,ii),0.5);
Table{i,j,ii}=y3;
end
end
end

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

### 채택된 답변

Geoff Hayes 2022년 4월 4일
@RP - look closely at this code
for i=1:4
for j=1:4
for ii=1:9
muy=-muinputs(i)*SCR;
sigmay=-sigmainputs(j)*SCR;
y(:,ii)=Testlooping(x,rho,muy,sigmay);
y2(:,ii)=x+y(:,ii);
y3(:,ii)=prctile(y2(:,ii),0.5);
Table{i,j,ii}=y3;
end
end
end
when ii is 1, then the code is doing
y(:,1)=Testlooping(x,rho,muy,sigmay);
y2(:,1)=x+y(:,1);
y3(:,1)=prctile(y2(:,1),0.5);
Table{i,j,1}=y3;
On the subsequent iteration, when ii is 2, then
y(:,2)=Testlooping(x,rho,muy,sigmay);
y2(:,2)=x+y(:,2);
y3(:,2)=prctile(y2(:,2),0.5);
Table{i,j,2}=y3;
Note that the assignment to Table{i,j,2} is y3 which combines the results of the current iteration and that of the previous. I don't think that you need to maintain this data on each iteration and so the code could be simplified to
y = Testlooping(x,rho,muy,sigmay);
y2 = x + y;
y3 = prctile(y2,0.5);
Table{i,j,2} = y3;

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

### 카테고리

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

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by