File Exchange

image thumbnail

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).

7 Downloads

Updated

View License

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]

Comments and Ratings (4)

Stephen Cobeldick

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

Stephen Cobeldick

@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

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

Imtiaz Hussain

Imtiaz Hussain (view profile)

Great Work

Updates

1.5

* Correct screenshot.

1.5

* Accept different input numeric types.
* Correct HTML doc example.

1.4

* fixed incorrect handling of fractional input values.

1.3

* Correct example outputs.

1.3

* Add UP, DOWN, and ARITHMETIC rounding options.

1.2

* Add HTML documentation.

1.2

* Change bonus function name to NUM2CIRCUIT.
* Change bonus function output array indexing.

1.1

- Edit blurb: why does the first newline always disappear?

MATLAB Release
MATLAB 7.11 (R2010b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today