How extract a function from a vector?

Hi all,
I have a question about defining function.
In my codes, I defined a vector in which each coordinates is a function of a variable (called m). The goal of my problem is to plot each coordinates of the vector separately. However when I try to define the coordinates as a function, I receive this error
indexing must appear last in an index expression. OR Unbalanced or unexpected parenthesis or bracket.
I tried the four following expressions
f1=@(m) VECTOR(1,1)(m);
f1=@(m) VECTOR(m)(1,1);
f1=@(m) (VECTOR(1,1))(m);
f1=@(m) (VECTOR(m))(1,1);
Does anyone have an idea?

 채택된 답변

Thibault
Thibault 2013년 2월 20일

0 개 추천

Works fine.
Thanks for your time.

댓글 수: 1

Jan
Jan 2013년 2월 20일
Please accept the answer which solves your problem. And post comments in the comment section, not as an answer. I suggest to delete this answer and accept the one, which helped. Thanks.

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2013년 2월 20일

0 개 추천

Are you trying to create a vector of functions, and in f1 trying to call the first function with the argument "m" ?
If so then you cannot do that using () to index into the vector. It was possible at one time, but it was ambiguous and was removed. Instead you must use a cell array of function handles.
f1 = @(m) VECTOR{1}(m);
Thibault
Thibault 2013년 2월 20일

0 개 추천

The problem is that I defined the vector using multiplication of matrices. So basically, the final vector is defined by inverting a matrix that depends on m.
And because this vector stands for the displacement of several elements, I need to plot each coordinates one by one

댓글 수: 1

So you are trying to call a function with m as its parameter, and that is going to return a vector, and then you wish to index the resulting vector? If so then there is no convenient syntax for doing that in MATLAB. It can be done using subref(), but nicer is to define an extra function to do the indexing.
First = @(v) v(1);
f1 = @(m) First(VECTOR(m));
where VECTOR is a function or function handle.

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

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

태그

질문:

2013년 2월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by