Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tab-completion of filenames as arguments for MATLAB scripts

Tags:

We all know MATLAB provides tab-completion for filenames used as arguments in MATLAB function like importdata,imread. How do we do that for the functions we create?

EDIT:

alt text

Displays the files and folders in the current directory.

like image 646
Jacob Avatar asked Dec 03 '09 20:12

Jacob


People also ask

Can Matlab accept function names as file names?

The name of the file must match the name of the first function in the file. In a script file which contains commands and function definitions. Functions must be at the end of the file. Script files cannot have the same name as a function in the file.


2 Answers

Caution: unsupported hack here.

Take a look at the file toolbox\local\TC.xml in your Matlab installation. This appears to contain the argument type mappings for tab completion. (I found this by just grepping the Matlab installation for "imread" in R2009b.)

Adding this line inside the <TC> element will get you tab-completion of file names for each of its arguments.

<binding name="importdata"        ctype="FILE"/> 

This requires modifying the Matlab installation in place. For some of the other files in toolbox/local, like classpath.txt, you can override them by placing modified copies in the directory you start Matlab from, but this didn't work for TC.xml for me.

like image 135
Andrew Janke Avatar answered Oct 13 '22 16:10

Andrew Janke


There is no supported way to add your functions to the argument Tab completion, but one trick I use is to put a "!" in front of the command so it is treated like a system command. Tab will then complete file paths. Once my MATLAB command is done, I home to the beginning of the line, delete the "!" and press enter.

like image 44
Mike Katz Avatar answered Oct 13 '22 17:10

Mike Katz