How do i find the smallest positive number?
31 views (last 30 days)
Show older comments
Xin Nian
on 15 Mar 2018
Commented: Stephen Driscoll
on 23 Feb 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
Accepted Answer
Walter Roberson
on 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{:});
0 Comments
More Answers (0)
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!