Generate anonymous functions from vectors

3 views (last 30 days)
For example, the vector [a b c ....], I want to generate an anonymous function fun=@(t) -(a*t(1)+b*t(2)+c*t(3)+.....) ,How to do it?

Accepted Answer

Matt J
Matt J on 29 Aug 2020
Edited: Matt J on 29 Aug 2020
fun=@(t) -( vector(:).' * t(:) )
  3 Comments
Walter Roberson
Walter Roberson on 30 Aug 2020
.' is transpose -- non-conjugate transpose.
vector(:) re-arranges the vector as a column vector no matter whether it was a row vector or column vector to start with. Transpose of that makes the column vector into a row vector. So vector(:).' is one way of forcing vector to be a row vector. Another way of writing it would be
reshape(vector,1,[])

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!