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?

 Akzeptierte Antwort

Thibault
Thibault am 20 Feb. 2013

0 Stimmen

Works fine.
Thanks for your time.

1 Kommentar

Jan
Jan am 20 Feb. 2013
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 20 Feb. 2013

0 Stimmen

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 am 20 Feb. 2013

0 Stimmen

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 Kommentar

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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by