# Preferred Number Rounding (Scripts) 1.0

Average Rating
User Rating:
Visitors Rating:
My rating:

See full specifications

## Preferred Number Rounding (Scripts) Publisher's description

### Round the elements of a numeric input vector to the nearest "preferred number" values.

Round the elements of a numeric input vector to the nearest "preferred number" values.

Why This Function?

Many parts and components in engineering and electronics are defined by "preferred value" or "preferred number" series. For example this includes the values of resistors, capacitors, inductors, screw sizes, metal thicknesses, motor ratings, cog teeth-count, etc. The results of your MATLAB calculations can use this function to automatically select the closest matching preferred values...

Or maybe you want to create a histogram with non-equally spaced edges (unlike MATLAB's evenly spaced "hist")...

Or maybe you need to round some numbers to arbitrary divisions, or want numbers that all start with the same digit/s...

This function rounds the elements of a horizontal numeric vector to values chosen from a preferred number series. The input values must be real, positive and finite.

The preferred number series may be one of:
# Standard series (1-2-5, Renard and electronic IEC 60063 are inbuilt).
# Custom series (repeating every decade, supplied as a numeric vector).
# Custom function (function in one variable).

### Examples ###

prefnum([514,7.6,37,0.9],'E6') % Electronic E6
ans = [470,6.8,33,1]

prefnum([514,7.6,37,0.9],'E12') % Electronic E12
ans = [560,8.2,39,0.82]

prefnum([514,7.6,37,0.9],'R10') % Renard R10.
ans = [500,8.0,40,1]

prefnum([514,7.6,37,0.9],'R"5') % Renard R"5
ans = [600,6.0,40,1]

prefnum([514,7.6,37,0.9],'125') % 1-2-5
ans = [500,10,50,1]

prefnum([514,7.6,37,0.9],[25,75]) % Custom vector (two steps per decade)
ans = [750,7.5,25,0.75]

prefnum([514,7.6,37,0.9],1) % Custom vector (one step per decade, nearest order of magnitude)
ans = [100,10,10,1]

prefnum([514,7.6,37,0.9],@(x)2^x) % Custom function (nearest binary / power of two)
ans = [512,8,32,1]

[A,B] = prefnum([5,300],'E12') % electronic E12 nearest to the integers 5 to 300
A = [4.7,330]
B = [4.7,5.6,6.8,8.2,10,12,15,18,22,27,33,39,47,56,68,82,100,120,150,180,220,270,330]

[~,~,E,H] = prefnum(1:149,'125',0) % Draw histogram of integers 1 to 149, with unequally spaced edges.
bar(H)
L = arrayfun(@num2str,E,'UniformOutput',false)
set(gca,'XTickLabel',strcat(L(1:end-1),'<',L(2:end)))

### Inbuilt Preferred Number Series ###

# 1-2-5 Series

# Electronic (IEC 60063) (resistors, capacitors, inductors, zener diodes...):

E6, E12, E24, E48, E96, E192

# Renard:

R5, R10, R20, R40, R80, R'5, R'10, R'20, R'40, R"5, R"10, R"20

#### System Requirements:

No special requirements.
Program Release Status: Minor Update
Program Install Support: Install and Uninstall

#### Preferred Number Rounding (Scripts) Tags:

Click on a tag to find related softwares

## Most Popular

ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation 1.1
ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation contain several functions for digital modulation simulation