Prev: Need help for "Indexing cannot yield multiple results"
Next: gaussian smoothing of a 1-D vector
From: Kenzo Mendoza on 10 Feb 2010 14:15 Let's say I have the following vector numb= [1.35, 4.62, 0, .53, .433, 0, 2.5 ] and I'm supposed to declare a variable that has the smallest value in numb vector, but zero is omitted So, .433 would be called out, not the 0's smallest_variable= .433 Any suggestions?
From: Loren Shure on 10 Feb 2010 14:22 In article <hkv0kb$3el$1(a)fred.mathworks.com>, kenzo_mendoza(a)knights.ucf.edu says... > Let's say I have the following vector > > numb= [1.35, 4.62, 0, .53, .433, 0, 2.5 ] > > and I'm supposed to declare a variable that has the smallest value in numb vector, but zero is omitted > > So, .433 would be called out, not the 0's > > smallest_variable= .433 > > Any suggestions? > Perhaps eliminate the 0s and the look for the minimum? Or look for the minimum, and if it's not 0, you're okay... Or sort the array and check the first value - if it's 0, check the next one, etc. -- Loren http://blogs.mathworks.com/loren http://matlabwiki.mathworks.com/MATLAB_FAQ
From: ImageAnalyst on 10 Feb 2010 14:24 Kenzo Mendoza: numb= [1.35, 4.62, 0, .53, .433, 0, 2.5 ] % Generate sample data numbNoZeros = numb; % Make a copy. numbNoZeros(numb==0) = []; % Get rid of zeros. [minValue minIndexes] = min(numbNoZeros) % Find the min value and position, not including zeros which are now gone.
From: Matt J on 10 Feb 2010 14:30 min(nonzeros(numb))
|
Pages: 1 Prev: Need help for "Indexing cannot yield multiple results" Next: gaussian smoothing of a 1-D vector |