File Exchange

## Round to Electronic Component Values

version 1.5 (27 KB) by

Round numeric array values to the best matching IEC 60063 resistor values (E-Series).

Updated

ROUND60063 rounds numeric values to the standard electronic component values defined in IEC 60063 (i.e. resistor, capacitor, and inductor values). The input may be a numeric scalar/vector/matrix/ND-array. The most appropriate rounded values are picked by calculating the rounding bin edges to approximate component tolerance boundaries. ROUND60063 returns the rounded values, the E-series values, the corresponding bin edges and indices. Supports E-series E3/E6/E12/E24/E48/E96/E192, eg E6 = [...,10,15,22,33,47,68,100,150,220,...].

### Bonus Functions ###

The bonus function ROUND60063_VIEW creates a figure that demonstrates how ROUND60063's rounding bin edges match the component tolerances. The rounding bin edges are calculated using the harmonic mean of adjacent E-series values.

The bonus function NUM2CIRCUIT uses an exhaustive search to find the component values whose equivalent circuit value is closest to the input value. The circuit can be either a parallel or series circuit (of resistors, capacitors, or inductors).

### Examples ###

round60063(500, 'E12')
ans = 470

round60063([5,18,42,100], 'E12')
ans = [4.7, 18, 39, 100]

round60063([5,18,42,100], 'E6')
ans = [4.7, 22, 47, 100]

round60063([5,18,42,100], 'E6', 'up')
ans = [6.8, 22, 47, 100]

round60063([5,18,42,100], 'E6', 'down')
ans = [4.7, 15, 33, 100]

round60063([5,18,42,100], 'E6', 'arithmetic')
ans = [4.7, 15, 47, 100]

[Y,pns,edg,idx] = round60063([5,18,42,100], 'E3')
Y = [4.7, 22, 47, 100]
pns = [4.7; 10; 22; 47; 100]
edg = [2.997; 6.395; 13.75; 29.97; 63.95; 137.5]
idx = [1, 3, 4, 5]

[Y,pns,edg,idx] = round60063([-Inf,Inf,NaN; -1, 0, 1], 'E3')
Y = [NaN, NaN, NaN; NaN, NaN, 1]
pns = 1
edg = [0.63946; 1.375]
idx = [NaN, NaN, NaN; NaN, NaN, 1]

Stephen Cobeldick

### Stephen Cobeldick (view profile)

@Austin White: I added 'up' and 'down' options.

Stephen Cobeldick

### Stephen Cobeldick (view profile)

@Austin White: one way to achieve this is:

>> X = [514, 1.9; 7.6, 37; 560, 39];
>> [~,pns] = round60063(X,'E12');

where this will round down:

>> [~,idx] = histc(X,pns);
>> pns(idx) % round down
ans =
470 1.8
6.8 33
560 39

and this will round up:

>> [~,idy] = histc(-X,-pns(end:-1:1));
>> pns(1+numel(pns)-idy) % round up
ans =
560 2.2
8.2 39
560 39

Austin White

### Austin White (view profile)

It would be great if you could say to round up or down.

Imtiaz Hussain

Great Work