Build a matrix for each loop output

2 visualizaciones (últimos 30 días)
Helder Maranhão
Helder Maranhão el 5 de Mzo. de 2022
Comentada: Helder Maranhão el 6 de Mzo. de 2022
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 comentarios
Matt J
Matt J el 5 de Mzo. de 2022
Yes, we can help, but please first post your code in copy/pastable form.
Helder Maranhão
Helder Maranhão el 6 de Mzo. de 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

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 6 de Mzo. de 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 comentario
Helder Maranhão
Helder Maranhão el 6 de Mzo. de 2022
Dear Matt
It worked perfectly.
Thank you very much.
Kind Regards
Helder

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by