I have a python code which I am trying to convert to Matlab code. The code is for baseline correction for a wave.
def baseline_als(y, lam, p, niter=20):
L = len(y)
D = sparse.csc_matrix(np.diff(np.eye(L), 2))
w = np.ones(L)
for i in xrange(niter):
W = sparse.spdiags(w, 0, L, L)
Z = W + lam * D.dot(D.transpose())
z = spsolve(Z, w*y)
w = p * (y > z) + (1-p) * (y < z)
return z
I have tried it converting like this.
function [z] = baseline_als(y, lam, p, niter=20)
L = len(y)
D = sparse.csc_matrix(diff(eye(L), 2))
w = ones(L)
for i = 1:niter
W = sparse.spdiags(w, 0, L, L) %Not working
Z = W + lam * dot(D,transpose(D))
z = spsolve(Z, w*y) % Not working
w = p * (y > z) + (1-p) * (y < z)
end % End of For loop
end % End of function
However there are no functions named spsolve and spdiag in octave/matlab. Is there any alternate function that I can use?
Aucun commentaire:
Enregistrer un commentaire