Build a matrix for each loop output

조회 수: 2 (최근 30일)
Helder Maranhão
Helder Maranhão 2022년 3월 5일
댓글: Helder Maranhão 2022년 3월 6일
Dear all
I would like to store each output from a loop to a matrix M.
I have some dificulties due to indexing.
Could someone plese give me a help on this problem?
Thank you very much
  댓글 수: 2
Matt J
Matt J 2022년 3월 5일
Yes, we can help, but please first post your code in copy/pastable form.
Helder Maranhão
Helder Maranhão 2022년 3월 6일
Dear Matt
Please find the code on a copy/pastable form. I have created a simplifed table, to run the code here. The values are diferent but the issur is the same.
Thank you for your help.
n1=([2 2 3 2 1 4])';
dbL1=([10 12 10 10 10 10])';
n2=([0 0 0 1 2 0])' ;
dbL2=([0 0 0 12 12 0])' ;
Asst=([0.00015708 0.00022619 0.0023562 0.00027018 0.00030473 0.00031416])';
Asneg =([0.00033466 0.0002799 0.0005958 0.00051939 0.00028386 0.0002758])';
As=table(n1, dbL1,n2,dbL2,Asst)
As = 6×5 table
n1 dbL1 n2 dbL2 Asst __ ____ __ ____ __________ 2 10 0 0 0.00015708 2 12 0 0 0.00022619 3 10 0 0 0.0023562 2 10 1 12 0.00027018 1 10 2 12 0.00030473 4 10 0 0 0.00031416
for j=1:3
As_prov=As.Asst>Asneg(j);
i=find(As_prov,1,'first')
n1=As.n1(i)
dbL1=As.dbL1(i)
n2=As.n2(i)
dbL2=As.dbL2(i)
end
i = 3
n1 = 3
dbL1 = 10
n2 = 0
dbL2 = 0
i = 3
n1 = 3
dbL1 = 10
n2 = 0
dbL2 = 0
i = 3
n1 = 3
dbL1 = 10
n2 = 0
dbL2 = 0

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

채택된 답변

Matt J
Matt J 2022년 3월 6일
M=zeros(3,4);
for j=1:3
As_prov=As.Asst>Asneg(j);
i=find(As_prov,1,'first')
M(j,1)=As.n1(i);
M(j,2)=As.dbL1(i);
M(j,3)=As.n2(i);
M(j,4)=As.dbL2(i);
end
  댓글 수: 1
Helder Maranhão
Helder Maranhão 2022년 3월 6일
Dear Matt
It worked perfectly.
Thank you very much.
Kind Regards
Helder

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by