MATLAB Examples

ROUND60063 Examples

The function ROUND60063 rounds the input numeric values to values from the IEC 60063 "Preferred Numbers" series. Most importantly ROUND60063 simulates the tolerance range of electronic components, so that the rounding bin edges correspond to the component tolerance limits. This means that the input values will be rounded within the component values' tolerance limits.

Contents

Basic Usage

ROUND60063 requires two inputs: the numeric array of values to be rounded, and the E-series (e.g. 'E24', 'E48', 'E96', etc.). ROUND60063's first output is an array of the input values rounded to IEC 60063 values:

round60063(500,'E6')
round60063(1:6,'E12')
ans =
   470
ans =
            1          2.2          3.3          3.9          4.7          5.6

Output 2: Preferred Number Series

ROUND60063's second output is a vector containing the E-series values over the entire range of all output values:

[out,pns] = round60063([1,101],'E3')
out =
     1   100
pns =
            1
          2.2
          4.7
           10
           22
           47
          100

Output 3: Bin Edges

The third output is a vector containing the bin edges corresponding to the Preferred Number Series, used to place the input values into bins (the section "Bin Edges and Component Tolerance" explains these values):

[~,~,bin] = round60063([1,101],'E3')
bin =
      0.63946
        1.375
       2.9971
       6.3946
        13.75
       29.971
       63.946
        137.5

Output 4: Indices

The fourth output is a vector of indices idx, such that the output out = pns(idx):

[out,pns,~,idx] = round60063([1,101],'E3')
pns(idx)
out =
     1   100
pns =
            1
          2.2
          4.7
           10
           22
           47
          100
idx =
     1     7
ans =
     1
   100

Input 3: Select Rounding Method

The optional third input argument can be used to select the rounding method, and can be specified as one of 'harmonic', 'arithmetic', 'up', or 'down':

ipt = [5,18,42,100];
round60063(ipt,'E6','harmonic') % default
round60063(ipt,'E6','arithmetic')
round60063(ipt,'E6','up')
round60063(ipt,'E6','down')
ans =
          4.7           22           47          100
ans =
          4.7           15           47          100
ans =
          6.8           22           47          100
ans =
          4.7           15           33          100

Component Tolerance and Bin Edges (Harmonic Mean)

The introduction mentions that ROUND60063 simulates the component tolerance range: it does this by computing the harmonic mean of adjacent Preferred Number Series (pns) values. The harmonic mean values simulate the tolerance ranges of the component values: the means are shown as vertical green lines in the figure below. These means are the bin edges used to round the input values into the IEC 60063 values (shown as blue diamonds):

round60063_view([5,23],'E6')

Example: Parallel Resistor Values with NUM2CIRCUIT

As a form of entertainment and example for ROUND60063 I wrote the function NUM2CIRCUIT (included with the ROUND60063 zip file) that finds parallel/series electronic component values to match the input value/s. For example, to find four E12 resistors that could be used in parallel with an equivalent circuit resistance closest to 123 Ohms:

[val,eqv] = num2circuit(123, 'E12', [10,1000], 4, true)
val =
   820   560   390   390
eqv =
       122.95

Example: Numeric to Metric Prefix with NUM2SIP

An easy way to convert the numeric values to strings with metric/SI prefixes (e.g. 1000 -> '1 k') is to use my FEX submission NUM2SIP:

% One single number:
num2sip(round60063(5e5,'E6'),[],true)
% Multiple numbers:
vec = round60063([123,4567,8e9],'E24');
strcat(arrayfun(@num2sip,vec,'UniformOutput',false),'Ohm')
ans =
470 kilo
ans = 
    '120 Ohm'    '4.7 kOhm'    '8.2 GOhm'