How to decipher matlab function syntax ambiguity -
this question has answer here:
- what @ operator in matlab? 3 answers
i cannot find syntax anywhere
y = @(beta, x)x*beta;
where x
vector or matrix lets say. @
used reference function can have more 1 externally visiuble function in same .m
file? sorry i'm new matlab can't find in documentation
that way define anonymous function in matlab. same
function result = y(beta, x) result = x * beta;
but without needing m-file or subfunction define it. can constructed within other m-files or within expression. typical use throw-away function inside call of complex function needs function 1 of inputs, i.e.:
>> arrayfun(@(x) x^2, 1:10) ans = 1 4 9 16 25 36 49 64 81 100
i use them lot refactor list of repetitive statements
a = complex_expression(x, y, z, 1) b = complex_expression(x, y, z, 3) c = complex_expression(x, y, z, 8)
into
f = @(n) complex_expression(x, y, z, n) = f(1) b = f(3) c = f(8)
more info mathworks. more or less same lambda expression in python.
Comments
Post a Comment