# R vs MATLAB – round 2

R takes it. I prefer coding in R over MATLAB. I feel R understands that I do not like to type too much. A few examples:

In order to include a default for a parameter in own function we do:
In R

So myfunction asks to specify x and TT, which are left with no default while DD is left alone and will take the value 2 during execution unless otherwise specified. Not too complicated.
In Matlab

Many more characters. This becomes very tedious when I write functions to be used by others with many arguments which I want to have default values for.

Plotting is another example, see the difference:

13 characters in R, about twice as much in Matlab, and I plot A LOT. A workaround is to write a function with your favorite specifications.

When I would not mind to type some more for clarity, Matlab does not like it. Sometimes I have a function with many arguments, so I do not remember the order in which they are defined. R is flexible like that:

Matlab:

In short, Matlab is waiting for the input in the same order and is not willing take a named argument. This means I need to remember if TT is second or third, otherwise I need to open the function and have a look. If you have 10 arguments and a bad memory, in order to execute, you have to first go over the function to remember which argument sits where in the sequence. I am not aware of any workaround for this nuisance.

### 3 comments on “R vs MATLAB – round 2”

1. C.Lin says:

Interesting comparison, most of the time it feels indeed coding in R is somehow more comfortable. As someone switching from MATLAB I’m loving R so far.

By the way the MATLAB plot in your plotting example could be done by
plot(x, ‘bo’)
While introducing a bit of ambiguity…

2. Mike says:

You can specify color and markers in MATLAB with fewer characters if you want:
>> x = 1:10;
>> plot(x, ‘ob-‘); %where ‘o’ is the marker ‘b’ is the color, and ‘-‘ is the line type
>> plot(x, ‘xr:’); %In this case, ‘x’ markers, ‘r’ed color, and ‘:’ dashed lines

3. John says:

I agree with you on these issues with respect to Matlab. Python versus R on this one would be harder.