Passion * Hope * Dream

小林的百科筆記

Above All

Last night I listened to the song 'Above All' while working on my project. It's been a while since I last listened to this song and it again reminded me of how great and how tender the love the Lord has for me. How precious that today I am loved by Him...



Above All

 

Verse 1: Above all powers

Above all kings

Above all nature

And all created things

Above all wisdom

And all the ways of man

You were here

Before the world began


Verse 2: Above all kingdoms

Above all thrones

Above all wonders

The world has ever known

Above all wealth

And treasures of the earth

There's no way to measure

What You're worth


CHORUS: Crucified

Laid behind a stone

You lived to die

Rejected and alone

Like a rose

Trampled on the ground

You took the fall

And thought of me

Above all


Repeat Verse 1

Repeat Verse 2

Repeat CHORUS (x2)

 

Like a rose

Trampled on the ground

You took the fall

And thought of me

Above all


There is no built-in function in Matlab to round a number to specific significant figures. However I have found a little trick from somewhere in the internet which works! It simply makes use of the 'mat2str' (or 'num2str') and 'eval' (or 'str2num') Matlab functions. For example, first generate a matrix 'A' with random numbers:

A = rand(2,3)*100

A =
70.6046 27.6923 9.7132
3.1833 4.6171 82.3458

Then convert into 'string' using 'mat2str' and specifies how many digits of precision, here I have made this to be 3:

>> A_temp = mat2str(A,3)

A_temp =
[70.6 27.7 9.71;3.18 4.62 82.3]

Now convert the string back to numerical values by using 'eval':

>> A_rounded = eval(A_temp)

A_rounded =
70.6000 27.7000 9.7100
3.1800 4.6200 82.3000


So the values have been rounded to 3 sig. fig. :-)

Now if we use 'num2str' instead of 'mat2str', we need to convert back to numerical values by using 'str2num' because 'eval' will not work. Moreover, I just found out that using 'num2str' can actually allow rounding to specific decimal places. Using the same 'A' matrix as above, and then specify the precision to be '%4.4e\n' which will round the values to the 4th decimal place:


A_temp2 = num2str(A,'%4.4e\n')

A_temp2 =
7.0605e+001
2.7692e+001
9.7132e+000
3.1833e+000
4.6171e+000
8.2346e+001

>> A_rounded2 = str2num(A_temp2)

A_rounded2 =
70.6050
27.6920
9.7132
3.1833
4.6171
82.3460

Noticed that it is necessary to have the '\n' in the string that specifies the format of precision, otherwise the result will go weird.

PS: I noticed that there are still small rounding errors (or floating point errors), however this trick should be good enough for general purposes.