I am just wondering if there is a list of the related Mathematica functions that correspond to Octave functions.
For example.
ones(n)
maps to Array[1 &, n]
I closed this question because rm -rf convinced me that what this answer was intended to do is ultimately impossible: that there is simply no way to give an approximate one-to-one mapping of functions between Octave/Matlab and Mathematica; apart from a few limited cases any recommendations are going to be localized and opinionated rather than truly informative.
This answer may remain for the time being but it should be considered deprecated.
As far as I know there isn't one, so let's make one together. This is a Community Wiki post.
The idea is for one person to give an Octave/Matlab function of interest and describe what it does, then other users can recommend substitutes. The community can improve and curate those recommendations. An example entry:
ones(n) builds an n-by-n array of ones
Array[1 &, {n,n}]
ConstantArray[1, {n,n}]
ones(n,1) builds an array of zeros of length n
As an alternative to the above
Range[n]^0
This is about as fast as ConstantArray
and it's shorter. :-)
zeros(n,1) builds an array of zeros of length n
Array[0 &, n]
ConstantArray[0, n]
Range[n] * 0
Also see ones above.
eye(n) builds the identity matrix of dimension n
IdentityMatrix[n]
for i=1:n ... end
Do[..., {i, 1, n}]
Use Table
instead of Do
to collect results into a list. See also Array
(and Function
).
IMAGE PROCESSING
Basic Import and Export
imread('image.png') Read image from graphics file
Import["image.png"]
imwrite(img,'image.png') Write image to graphics file
Export["image.png","png"]
Image Type Conversion
rgb2gray(img) Convert RGB image or colormap to grayscale
ColorConvert[img, "Grayscale"]
ones
is a bit like this function for obtaining $2^n$: powerof2[n_] := Length@ReplaceRepeated[{0}, (0 -> Sequence[0, 0]), MaxIterations -> n] // Quiet
$\endgroup$
for
, it's going to take a while and will include Outer
, Inner
, Map
, Apply
, Cases
, Select
, and many more functions. That's exactly why I don't think it's a good idea to learn Mathematica based on such a list.
$\endgroup$
ones(n)
probably would beConstantArray[1, n]
. However, that creates a list (or vector) ofInteger
entries, which means that if you try to do any arithmetic with it it will be done with exact numbers. This is much slower than with reals. This sort of booby traps are everywhere in mma. $\endgroup$res = sort(a)
does the same asres = Sort[a]
, but[~, ind] = sort(a)
isind = Ordering[a]
despite the function being calledsort
. And then[res, ind] = sort(a)
is{res, ind} = Through[{Sort, Ordering}[a]]
or{res, ind} = {a[[#]], #} &@Ordering@a
, both of which would be too advanced for someone making the transition from MATLAB to Mathematica. $\endgroup$