How do i find the smallest positive number?
31 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Xin Nian
am 15 Mär. 2018
Kommentiert: Stephen Driscoll
am 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
1 Kommentar
Akzeptierte Antwort
Walter Roberson
am 15 Mär. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!