Matlab, quick review
Aug. 8th, 2008 12:56 am* sweet syntactic sugar for matrix operations (transpose, submatrix, etc.)
* very easy to write unreadable code, full of poorly-named variables
* the semantics seems to be unnecessarily complex
* argh, please please let me define nameless functions, on the fly!
I know how to do entry-wise application (i.e. "mapcar" for the Lispers) when it's an infix operator: e.g. use ".*" instead of "*". But I can't do this for my own functions, and need to write for-loops.
A very odd thing: apparently, functions can't refer to constants/variables defined outside of it (the only constants allowed seem to be literals such as "1" and pre-defined constants, such as "pi").
Hopefully, I'm missing something.
* very easy to write unreadable code, full of poorly-named variables
* the semantics seems to be unnecessarily complex
* argh, please please let me define nameless functions, on the fly!
I know how to do entry-wise application (i.e. "mapcar" for the Lispers) when it's an infix operator: e.g. use ".*" instead of "*". But I can't do this for my own functions, and need to write for-loops.
A very odd thing: apparently, functions can't refer to constants/variables defined outside of it (the only constants allowed seem to be literals such as "1" and pre-defined constants, such as "pi").
Hopefully, I'm missing something.
(no subject)
Date: 2008-08-08 06:00 am (UTC)Mapcar
Date: 2008-08-08 07:08 am (UTC)arrayfun(@your_function_name, your_array)
See also cellfun. Matlab doesn't handle for loops well, so if you can avoid them you'll save a lot of time.
Re: Mapcar
Date: 2008-08-09 01:22 am (UTC)Nameless function
Date: 2008-08-08 11:09 am (UTC)anonymous functions
f = @(x) x^2+2x
- scott
Re: Nameless function
Date: 2008-08-08 12:04 pm (UTC)And I see you've already noticed MATLAB's delightful scoping. Don't use "evalin", okay? Just pass what you need. Stick it all in a struct if you have to.
Don't forget that you can create a new variable inside a block and refer to it outside of the block later, i.e.
function foo=myfunc
if true
a = 10;
end
foo = a^2;
Re: Nameless function
Date: 2008-08-08 05:15 pm (UTC)Scott who?
Re: Nameless function
Date: 2008-08-09 01:22 am (UTC)(no subject)
Date: 2008-08-08 12:15 pm (UTC)