Build a matrix for each loop output

2 次查看(过去 30 天)
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

更多回答(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