# Is there a list of Octave functions mapped to the related Mathematica one? [closed]

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]

• You might look for matlab-mathematica functions. But keep in mind that, as a language, mathematica is very different from matlab or octave. – acl Jul 22 '14 at 12:29
• I understand; like I said, you might have better luck looking for matlab-mathematica tables. Also, a more direct translation of ones(n) probably would be ConstantArray[1, n]. However, that creates a list (or vector) of Integer 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. – acl Jul 22 '14 at 12:42
• there are lots of problems solved by Matlab and Mathematica side-by-side here – Nasser Jul 22 '14 at 14:30
• I can certainly see why you are looking for such a list. I have wished for similar lists before. But beware: Mathematica and MATLAB are very different. Using such a list means that you are thinking in MATLAB/Octave and trying to impose that style on Mathematica, which is going to be a disaster. (I'm saying this based on personal experience when I was learning R, and R is close to Mathematica than Mathematica is to Octave.) – Szabolcs Jul 22 '14 at 16:36
• @Mr.Wizard As an example for the multiple outputs comment, consider sorting: res = sort(a) does the same as res = Sort[a], but [~, ind] = sort(a) is ind = Ordering[a] despite the function being called sort. 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. – rm -rf Jul 22 '14 at 18:08

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

ones(n) builds an n-by-n array of ones

1. Array[1 &, {n,n}]

2. 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

zeros(n,1) builds an array of zeros of length n

1. Array[0 &, n]

2. ConstantArray[0, n]

3. Range[n] * 0

Also see ones above.

### eye

eye(n) builds the identity matrix of dimension n

 IdentityMatrix[n]


### for

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

 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"]


• The 3rd alternative for ones is a bit like this function for obtaining $2^n$: powerof2[n_] := Length@ReplaceRepeated[{0}, (0 -> Sequence[0, 0]), MaxIterations -> n] // Quiet – acl Jul 22 '14 at 16:10
• @Mr.Wizard Oh, I just found this on Wikipedia: "In fact, Octave treats incompatibility with MATLAB as a bug [...]". I think we are safe :) – sebhofer Jul 22 '14 at 16:55
• @Mr.Wizard Well, if we want to list all ways to replace MATLAB's 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. – Szabolcs Jul 22 '14 at 17:07
• @Szabolcs I hope no one thinks this is the right way to learn Mathematica. Rather I hope it becomes a useful reference for those making the transition. I'm sure there are many possibilities for getting lost down the rabbit hole but that's what curation is for. – Mr.Wizard Jul 22 '14 at 17:10
• @Simon There's actually a Q&A for that alone; it happens to be mine: (7924) – Mr.Wizard Jul 22 '14 at 17:12