Angharad has asked for the wisdom of the Perl Monks concerning the following question:

I've looked though various documentation but can't make head or tail on how to go about the following. In a nutshell, i have a matlab command that I need to convert into perl. I'm attempting to do this via PDL. The matlab command is as follows.
ns =2; [U,S,V] = svd(A,0); #v transposed Vt = V'; #reconstruct the data using a specified number of the most significant + datasets recA = U(:,1:ns)*S(1:ns,1:ns)*Vt(1:ns,:)
Now although I have now managed to produce the the matrices in question (using SVD function in PDL) I'm slightly bemused as to how to go about creating the 'RecA' matrix. I've been reading about PDL::slice and have worked out how to extract certain values from a PDL matrix but have to admit I am a bit lost. Any help would be appreciated, as always.

Replies are listed 'Best First'.
Re: matlab to perl
by newroz (Monk) on Aug 12, 2005 at 11:57 UTC
    There is a PDL::NiceSlice which claims to have much more nicer syntax.
    I haven't tested it.
    use PDL::NiceSlice; #something......... recA = $U(:,1:$ns)*$S(1:$ns,1:$ns)*$Vt(1:$ns,:);

    Hope that is what you seeked.
Re: matlab to perl
by Anonymous Monk on Aug 13, 2005 at 00:30 UTC
    Why are you trying to do this in the first place? You seem to have a functioning application in MatLab and you want to mess with it by moving it to perl. If it is a case that you don't want to spend money on more MatLab licences, then just use Octave. Octave runs Matlab code directly.

    It's nothing against perl, I'm sure it can do it. But it might not be the most productive time spent.