How do i find the smallest positive number?

31 vues (au cours des 30 derniers jours)
Xin Nian
Xin Nian le 15 Mar 2018
Commenté : Stephen Driscoll le 23 Fév 2020
I am making a function that finds the Pivot Element of a Tableau. However everything seems to works fine beside Line 13 [ValR,Row]=min(PivotR./tableau(2:a,b)). ValR will only be the smallest number in the given range, not just positive. min function gives the smallest number(including negative). Is there something i can use instead of min function?
function pivotElement = getPivot(tableau)
pivotElement = 0
pivotCol = 0
[a,b]=size(tableau)
FirstRow=tableau(1,1:b-1)
[ValC,Column]= min(FirstRow)
if(ValC< 0)
pivotCol = Column
end;
pivotRow=0
PivotR=tableau(2:a,pivotCol)
[ValR,Row]=min(PivotR./tableau(2:a,b))
if(ValR > 0)
pivotRow = Row
end;
if ((pivotRow~=0)&&(pivotCol==0))
pivotElement = 0
end
if ((pivotRow==0)&&(pivotCol~=0))
pivotElement = 1
end
if ((pivotRow~=0)&&(pivotCol~=0))
pivotElement = [pivotRow;pivotCol]
end
end
  1 commentaire
Stephen Driscoll
Stephen Driscoll le 23 Fév 2020
index = find(A == min(A(A>0)))

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 15 Mar 2018
There is no built-in command for that.
function [mins, idxes] = minpositive(Array, varargin)
Array(Array<=0) = nan;
[mins, idxes] = min(Array, varargin{:});

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by