Hi all
i want to extract the minimum positive value in each column, i have used this code
for j=1:length(columnA)
a(j)=min(A(A(:,j)>0));
end
but i am not able to solve the problem. A is a matrix
Thank for the help

 Respuesta aceptada

Matt J
Matt J el 14 de Ag. de 2020
Editada: Matt J el 14 de Ag. de 2020

0 votos

We don't know what columnA is in the code that you've shown. It would have to be a vector with the same number of columns as A for the code to work.
Regardless, the complete operation can easily be done without looping:
B=A: B(A<=0)=+inf;
a=min(B,[],1);

4 comentarios

EldaEbrithil
EldaEbrithil el 14 de Ag. de 2020
length(columnA) is the number of column of the A matrix
EldaEbrithil
EldaEbrithil el 14 de Ag. de 2020
it gives me this error
Maximum variable size allowed by the program is exceeded.
Matt J
Matt J el 14 de Ag. de 2020
Editada: Matt J el 14 de Ag. de 2020
As I said, it doesn't matter. You don't need the loop. But if you were to use a loop, it would be
for j=1:size(A,2)
a(j)=min( A( A(:,j)>0 , j) );
end
EldaEbrithil
EldaEbrithil el 14 de Ag. de 2020
Thank you very much, now it works!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2019a

Etiquetas

Preguntada:

el 14 de Ag. de 2020

Comentada:

el 14 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by