File Exchange

## Round to Electronic Component Values

version 1.5.0.2 (26.6 KB) by Stephen Cobeldick

### Stephen Cobeldick (view profile)

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

Updated 16 Feb 2020

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,42,18,100], 'E12')
ans = [4.7, 39, 18, 100]

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

>> [Y,pns,edg,idx] = round60063([5,42,18,100], 'E3')
Y = [4.7, 47, 22, 100]
pns = [4.7; 10; 22; 47; 100]
edg = [2.997; 6.395; 13.75; 29.97; 63.95; 137.5]
idx = [1, 4, 3, 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]

### Cite As

Stephen Cobeldick (2020). Round to Electronic Component Values (https://www.mathworks.com/matlabcentral/fileexchange/48840-round-to-electronic-component-values), MATLAB Central File Exchange. Retrieved .

Heinz-Peter Liechtenecker

David Ward

### David Ward (view profile)

Nice add on, very handy. Thanks.

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