How do i find the smallest positive number?

31 次查看(过去 30 天)
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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by