Generate anonymous functions from vectors

조회 수: 2 (최근 30일)
Yang Metin
Yang Metin 2020년 8월 29일
댓글: Walter Roberson 2020년 8월 30일
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?

채택된 답변

Matt J
Matt J 2020년 8월 29일
편집: Matt J 2020년 8월 29일
fun=@(t) -( vector(:).' * t(:) )
  댓글 수: 3
Yang Metin
Yang Metin 2020년 8월 30일
What does " .' " do?
Walter Roberson
Walter Roberson 2020년 8월 30일
.' 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,[])

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by