l = 1000
a = rand(l,2);
b = rand(1,2);
tic
for t = 1:1000
c = bsxfun(@plus,a,b);
end
toc
tic
for t = 1:1000
c = a+repmat(b,l,1);
end
toc
MATLAB best practice
Thursday, February 5, 2015
Choose bsxfun instead of repmat for faster code
I have recognized that using the repmat function might slow the code, it is significantly faster to use bsxfun, see the code snipplet below, bsxfun is about five times faster.
Friday, March 1, 2013
How to open matlab without screen
If you have only a terminal, MATLAB will run without display anyway, but in some cases, for instance if you would like to save memory and processor it is worth to run without screen as
matlab -nodisplay
Thursday, February 28, 2013
Edit matlab scripts and functions in vim
Good resources for editing MATLAB files in vim can be found here
http://www.vim.org/scripts/script.php?script_id=2407
http://www.vim.org/scripts/script.php?script_id=2407
How to open a file for debug when error
If you have an error in your code the default functionality of MATLAB is to stop, however if you configure Debug / "stop if errors \ warnings" to always stop if error (dbstop if error) the file with error will be opened in debug mode in case of error.
Subscribe to:
Posts (Atom)