gusl: (Default)
[personal profile] gusl
* 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.

(no subject)

Date: 2008-08-08 06:00 am (UTC)
From: [identity profile] bhudson.livejournal.com
If you are writing for loops, you're doing something wrong, and matlab will hurt you for it. Unfortunately, I haven't hacked matlab in a very long time so I can't actually help you.

Mapcar

Date: 2008-08-08 07:08 am (UTC)
From: [identity profile] marymcglo.livejournal.com
Is this what you're looking for?

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.

Nameless function

Date: 2008-08-08 11:09 am (UTC)
From: (Anonymous)
define nameless functions, on the fly:
anonymous functions
f = @(x) x^2+2x

- scott

Re: Nameless function

Date: 2008-08-08 12:04 pm (UTC)
From: [identity profile] stepleton.livejournal.com
Yeah, that's how it's done in MATLAB (Now With Closures!). Hope you can do it all in one line. And Benoit is right: loops when you're learning usually == fail.

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;

(no subject)

Date: 2008-08-08 12:15 pm (UTC)
From: [identity profile] altamira16.livejournal.com
feval is also useful to know. Carry on.

Re: Nameless function

Date: 2008-08-08 05:15 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
Awesome! so @ is like lambda?

Scott who?

Re: Nameless function

Date: 2008-08-09 01:22 am (UTC)
From: [identity profile] gustavolacerda.livejournal.com
'@' and 'arrayfun' were exactly what I needed! Thanks.

Re: Mapcar

Date: 2008-08-09 01:22 am (UTC)
From: [identity profile] gustavolacerda.livejournal.com
'@' (i.e. lambda) and 'arrayfun' were exactly what I needed! Thanks.

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags