it's just a change-of-base to convert the base of the logarithm, you can just use logm as follows:

log2m=logm(M) ./ log(2);
Answer from bla on Stack Overflow
🌐
MathWorks
mathworks.com › matlab › mathematics › elementary math › exponents and logarithms
log2 - Base 2 logarithm and floating-point number dissection - MATLAB
Exponent values, returned as a ... X = F.*2.^E. This function corresponds to the ANSI® C function frexp() and the IEEE® floating-point standard function logb(). Any zeros in X produce F = 0 and E = 0. ... The log2 function fully supports tall arrays. For more information, see Tall Arrays.
🌐
MathWorks
mathworks.com › symbolic math toolbox › mathematics › mathematical functions
log2 - Base-2 logarithm of symbolic input - MATLAB
For the syntax [F,E] = log2(X), any zeros in X produce F = 0 and E = 0. Input values of Inf, -Inf, or NaN are returned unchanged in F with a corresponding exponent of E = 0. ... Base-2 logarithm values, returned as a symbolic number, vector, matrix, or array of the same size as X.
🌐
Johns Hopkins University
math.jhu.edu › ~shiffman › 370 › help › techdoc › ref › log2.html
log2 (MATLAB Function Reference)
Description Y = log2(X) computes the base 2 logarithm of the elements of X. [F,E] = log2(X) returns arrays F and E. Argument F is an array of real values, usually in the range 0.5 abs(F) < 1. For real X, F satisfies the equation: X = F.*2.^E.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 365748-how-to-write-log-base-2-in-matlab-coding
how to write log base 2 in matlab coding - MATLAB Answers - MATLAB Central
November 8, 2017 - https://www.mathworks.com/matlabcentral/answers/365748-how-to-write-log-base-2-in-matlab-coding#answer_1054975 · Cancel Copy to Clipboard · To find the log in any base, make use of the base-change formula: log_b(x) = log_a(x)/log_a(b) So you ...
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1465394-how-do-i-calculate-a-logarithm-of-a-variable-base
How do I calculate a logarithm of a variable base? - MATLAB Answers - MATLAB Central
October 2, 2021 - Hi! I tried to calculate a log of a varying base - no success. I saw that calculating log of the base of 10 or e is possible. for an example: after typing log (a,b) - I recieve an ERROR message. ...
Find elsewhere
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1802695-how-can-i-take-the-log2-of-x-plus-1-of-a-matrix
How can i take the log2 of x plus 1 of a matrix - MATLAB Answers - MATLAB Central
September 10, 2022 - Y = LOG2(X) is the base 2 logarithm of the elements of X. [F,E] = LOG2(X) for each element of the real array X, returns an array F of real numbers, usually in the range 0.5 <= abs(F) < 1, and an array E of integers, so that X = F .* 2.^E.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 579159-logarithmic-scale-with-a-different-base
Logarithmic scale with a different base - MATLAB Answers - MATLAB Central
August 13, 2020 - https://www.mathworks.com/matlabcentral/answers/579159-logarithmic-scale-with-a-different-base#answer_479331 · Cancel Copy to Clipboard · log2(x) = log(x) *log(2) log(2) is a uniform scaling and since plots are scaled to fit available space, ...
🌐
Scilab
help.scilab.org › docs › 5.4.1 › en_US › m2sci_log2.html
log2 (Matlab function) - Base 2 logarithm and dissect floating point number
April 2, 2013 - Please note that the recommended version of Scilab is 2026.0.1. This page might be outdated. However, this page did not exist in the previous stable version. Scilab help >> Matlab to Scilab Conversion Tips > Matlab-Scilab equivalents > L > log2 (Matlab function) Base 2 logarithm and dissect floating point number
🌐
Quora
quora.com › How-can-I-implement-log-ln-and-e-in-MATLAB
How to implement log, ln, and e in MATLAB - Quora
MATLAB already provides the standard ... ... Natural log: log(x) returns ln(x) (base e). Base-10 log: log10(x). Base-2 log: log2(x)....