Azzera filtri
Azzera filtri

Build a matrix for each loop output

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Matt J
Matt J il 5 Mar 2022
Yes, we can help, but please first post your code in copy/pastable form.
Helder Maranhão
Helder Maranhão il 6 Mar 2022
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

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 6 Mar 2022
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 Commento
Helder Maranhão
Helder Maranhão il 6 Mar 2022
Dear Matt
It worked perfectly.
Thank you very much.
Kind Regards
Helder

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by