Question: I programmed in [MATLAB](http://www.mathworks.com/) for many years, but switched to using R exclusively in the past few years so I'm a little out of practice. I'm interviewing a candidate today who describes himself as a MATLAB expert. 

What MATLAB interview questions should I ask?

Some other sites with resources for this:

* ["Matlab interview questions" on Wilmott](http://www.wilmott.com/messageview.cfm?catid=10&threadid=51640)
* ["MATLAB Questions and Answers" on GlobaleGuildLine](http://www.globalguideline.com/interview_questions/Questions.php?sc=MATLAB_Interview_Questions_and_Answers)
* ["Matlab Interview Questions" on CoolInterview](http://www.coolinterview.com/type.asp?iType=453)

Answer: 
This is a bit subjective, but I'll bite... ;)

For someone who is a self-professed MATLAB expert, here are some of the things that I would personally expect them to be able to illustrate in an interview:

* How to use the [arithmetic operators](http://www.mathworks.com/access/helpdesk/help/techdoc/ref/arithmeticoperators.html) for matrix *or* element-wise operations.
* A familiarity with all the basic [data types](http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f2-43934.html) and how to convert effortlessly between them.
* A complete understanding of matrix indexing and assignment, be it logical, linear, or subscripted indexing (basically, everything on [this page of the documentation](http://www.mathworks.com/access/helpdesk/help/techdoc/math/f1-85462.html)).
* An ability to [manipulate multi-dimensional arrays](http://www.mathworks.com/access/helpdesk/help/techdoc/math/f1-86528.html).
* The understanding and regular usage of optimizations like [preallocation](http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f8-784135.html#f8-793781) and [vectorization](http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f8-784135.html#br8fs0d-1).
* An understanding of how to handle [file I/O](http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f10-61355.html) for a number of different situations.
* A familiarity with [handle graphics](http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f3-15974.html) and all of the [basic plotting capabilities](http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f3-27853.html).
* An intimate knowledge of [the types of functions in MATLAB](http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f4-62416.html), in particular [nested functions](http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f4-39683.html). Specifically, given the following function:

```
function fcnHandle = counter
  value = 0;
  function currentValue = increment
    value = value+1;
    currentValue = value;
  end
  fcnHandle = @increment;
end

```

They should be able to tell you what the contents of the variable `output` will be in the following code, *without* running it in MATLAB:

```
>> f1 = counter();
>> f2 = counter();
>> output = [f1() f1() f2() f1() f2()];  %# WHAT IS IT?!

```
I. I think [this recent SO question](https://stackoverflow.com/questions/2435018/two-arrays-defining-2d-coordinates-as-array-indices-in-matlab-octave)
 on indexing is a very good question
 for an "expert".

> 
> I have a 2D array, call it 'A'. I have
>  two other 2D arrays, call them 'ix'
>  and 'iy'. I would like to create an
>  output array whose elements are the
>  elements of A at the index pairs
>  provided by x\_idx and y\_idx. I can do
>  this with a loop as follows:
> 
> 
> 
> ```
> for i=1:nx
>      for j=1:ny
>          output(i,j) = A(ix(i,j),iy(i,j));
>      end 
> end
> 
> ```
> 
> How can I do this without the loop? If
>  I do output = A(ix,iy), I get the
>  value of A over the whole range of
>  (ix)X(iy).
> 
> 
> 

II. Basic knowledge of operators like element-wise multiplication between two matrices (`.*`).

III. Logical indexing - generate a random symmetric matrix with values from `0-1` and set all values above `T` to 0.

IV. Read a file with some properly formatted data into a matrix (`importdata`)

V. Here's [another sweet SO question](https://stackoverflow.com/questions/2425066/matlab-comparing-all-elements-in-three-arrays)

> 
> I have three 1-d arrays where elements
>  are some values and I want to compare
>  every element in one array to all
>  elements in other two.
> 
> 
> For example:
> 
> 
> 
> ```
> a=[2,4,6,8,12]
> b=[1,3,5,9,10]
> c=[3,5,8,11,15]
> 
> ```
> 
> I want to know if there are same
>  values in different arrays (in this
>  case there are 3,5,8)
> 
> 
> 

**Btw**, there's an excellent chance your interviewee will Google "MATLAB interview questions" and see this post :)