If you are a MATLAB user, this page is for you. It explains the key differences between MATLAB and PDL to help you get going as quickly as possible.
This document is not a tutorial. For that, go to the PDL Quick Start guide. This document complements the Quick Start guide, as it highlights the differences between MATLAB and PDL.
The key difference between MATLAB and PDL is PERL.
Perl is a general purpose programming language with thousands of modules freely available on the web. PDL is an extension of Perl. This gives PDL programs access to more features than most numerical tools can dream of.
Perl itself has excellent documentation at http://perldoc.perl.org. Or use the command perldoc perl.
To search through Perl modules, go to http://www.cpan.org
Like MATLAB, PDL is an array-based numerical programming language. This section covers the basic array syntax.
The shell
Run the **perldl** command to start the PDL interactive shell.
Variables
In Perl, variables always start with the '$' sign. value = 42 MATLAB $value = 42 PDL
Array
Use the "pdl" constructor to create a new PDL object. v = [1,2,3,4] MATLAB $v = pdl [1,2,3,4] PDL
Matrix
A = [ 1,2,3 ; 3,4,5 ] MATLAB $A = pdl [ [1,2,3] , [3,4,5] ] PDL
Display a matrix
disp(A) MATLAB print $A PDL p $A PDL
Matrix multiplication
A * B MATLAB $A x $B PDL
Component-wise multiplication
A .* B MATLAB $A * $B PDL
Transpose
A' MATLAB transpose $A PDL
Create a matrix of zeros
A = zeros(5) MATLAB $A = zeros 5,5 PDL
Create a matrix of ones
A = ones(5) MATLAB $A = ones 5,5 PDL
Create a random matrix
A = rand(5) MATLAB $A = random 5,5 PDL
Average of a matrix along one dimension
mean(A) MATLAB average $A PDL
Average of all elements in a matrix
mean(A(:)) MATLAB avg $A PDL
Sum of a matrix along one dimension
sum(A) MATLAB sumover $A PDL
Sum of all elements in a matrix
sum(A(:)) MATLAB sum $A PDL
Maximum of a matrix along one dimension
max(A) MATLAB maximum $A PDL
Maximum of all elements in a matrix
max(A(:)) MATLAB max $A PDL
Minimum of a matrix along one dimension
min(A) MATLAB minimum $A PDL
Minimum of all elements in a matrix
min(A(:)) MATLAB min $A PDL
Generate linearly spaced vector
linspace(a,b,n) MATLAB zeroes(n)->xlinvals(a,b) PDL
Trig functions: sin, cos, tan, asin, acos, atan
Same in both languages.
Exponential and Log: exp, log, log10
Same in both languages.
Dimension sizes
size(A) MATLAB shape $A PDL (see also dims $A which returns a perl list/array)
Number of dimensions
ndims(A) MATLAB ndims $A PDL
Number of elements
numel(A) MATLAB nelem $A PDL
A standard conditional ("if-statement") in Perl behaves like the one in MATLAB, with a more C-like syntax:
% MATLAB conditional if value > MAX disp("Value too large") elseif value
use tables?
Perhaps we should consider making a table comparing IDL, PDL, Matlab, and Numpy? Here's an example table taken from the 2009 Fall Survey:
and it renders like this:
Which of these best describes your use of PDL?
Answer Respondents Percent
I write code that directly uses PDL on a regular basis.
24
49%
I make regular use of PDL through a script I wrote a while back, but I don't directly use PDL much.
10
20.4%
I used to use PDL, but now I primarily use some other software for numeric programming.
5
10.2%
I could never get PDL to install.
4
8.2%
I think it might be useful but I could never figure out how to use it for my needs.
6
12.2%