0

I am converting matlab code to python code

function Xn = ReSampleCurve(X,N)

    [n,T] = size(X);
    del(1) = 0;
    for r = 2:T
        del(r) = norm(X(:,r) - X(:,r-1));
    end
    cumdel = cumsum(del)/sum(del);   

    newdel = [0:N-1]/(N-1);

    for j=1:n
        Xn(j,:) = interp1(cumdel,X(j,1:T),newdel,'linear');
    end

I want to convert this into python code

The input values are :

X = [[-9.035250067710876, 7.453250169754028, 33.34074878692627], [-6.63700008392334, 5.132999956607819, 31.66075038909912],[-5.1272499561309814, 8.251499891281128, 30.925999641418457], [-5.1272499561309814, 8.251499891281128, 30.925999641418457]]
N = 200

can anyone explains me what these lines do?

    del(1) = 0;
    for r = 2:T
        del(r) = norm(X(:,r) - X(:,r-1));
1
  • 1
    you can always try freemat.sourceforge.net and run the matlab-code to see for yourself... Commented Jan 9, 2014 at 11:27

2 Answers 2

1

For what it is worth, here is the vectorized way to get del(2:end) in Matlab, perhaps this makes more sense to you:

sqrt(sum(diff(M,1,2).^2))
Sign up to request clarification or add additional context in comments.

Comments

1

del is an array in the MATLAB code. So del(1) = 0 is equivalent to del_list = [0] (MATLAB arrays a 1-indexed, del is a reserved word in python).

In the for loop, this is equivalent to:

for r in range(1,T):
    del_list.append(norm(X[:,r] - X[:,r-1]))

The above won't work in pure python (array subtraction won't work). You'd have to add in numpy or numeric) - but hopefully you get the idea.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.