take the base-10 logarithm of a number in matlab

To take the base-10 logarithm of a number in MATLAB, you should use the log10() function.

Here's an example code snippet:

main.m
x = 100;
y = log10(x);
disp(y);
32 chars
4 lines

This code will output the value 2, because log10(100) equals 2.

You can also use the shorthand log() function to take the logarithm of a number with a different base. For example, to take the base-e (natural) logarithm of a number, use log() without any arguments. To take the base-2 logarithm of a number, use log2().

gistlibby LogSnag