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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by