For Programmers: Free Programming Magazines  


Home > Archive > Matlab > December 2005 > selecting an element form a matrix with feval









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author selecting an element form a matrix with feval
Adi

2005-12-12, 7:23 pm

Dear all,

How do you select an element from a matrix using the function feval?
The traditional way to select the element on the 2nd row and 3rd
column of matrix A is A(2,3). But in nested functions this syntax is
not useful, the feval syntax should be used. But how? feval(A,2,3)
does not work, neither does feval(A(2,3)). Can anyone help?

Thx!

Adi
Peter Bone

2005-12-12, 7:23 pm

feval stands for function evaluation. You give it the name of a function as a string and the input variables and it runs the function. I don't see how it could be used to select an element from a matrix or why the basic A(row,col) wouldn't work. Can you m
aybe explain a bit more. If you found this thing about using feval in the help files can you tell me how to get to it.

Peter Bone
PB

2005-12-12, 7:23 pm

Adi wrote:
>
>
> Dear all,
>
> How do you select an element from a matrix using the function
> feval?
> The traditional way to select the element on the 2nd row and 3rd
> column of matrix A is A(2,3). But in nested functions this syntax
> is
> not useful, the feval syntax should be used. But how? feval(A,2,3)
> does not work, neither does feval(A(2,3)). Can anyone help?
>
> Thx!
>
> Adi


Can you explain why normal indexing wouldn´t work in your case?

/PB
adi

2005-12-12, 7:23 pm

Well, let me give you a concrete example. Suppose A is a cell array
containg e.g. the 5x6 array B on position A{2,3}. From this array,
suppose you are interested in B(3,4). The non-nested version to get
to this element is: B = A{2,3}; B[5,6]. But suppose you want to nest
it: A{2,3}[5,6]. This does not work! Normally in these situations the
function feval is used. In pseudocode: feval(feval(element, 5, 6,
(element, 2, 3, A)). But what is the exact Matlab syntax to note
such? Thx for help...
Christopher Hulbert

2005-12-12, 7:23 pm

adi wrote:
> Well, let me give you a concrete example. Suppose A is a cell array
> containg e.g. the 5x6 array B on position A{2,3}. From this array,
> suppose you are interested in B(3,4). The non-nested version to get
> to this element is: B = A{2,3}; B[5,6]. But suppose you want to nest
> it: A{2,3}[5,6]. This does not work!


Of course it doesn't work, square brackets are not for that purpose nor for the
syntax B[5,6] i believe.

Normally in these situations the
> function feval is used. In pseudocode: feval(feval(element, 5, 6,
> (element, 2, 3, A)). But what is the exact Matlab syntax to note
> such? Thx for help...


What version of matlab do you have?

R14 SP3 and R13 give me:
[color=darkred]

B =

0.9169

feval takes as it's first argument a function handle which A is not.
Loren Shure

2005-12-12, 7:23 pm

In article <ef1e988.-1@webx.raydaftYaTP>,
aditya_nospam_@biomath_nospam_.ugent.be says...
> Dear all,
>
> How do you select an element from a matrix using the function feval?
> The traditional way to select the element on the 2nd row and 3rd
> column of matrix A is A(2,3). But in nested functions this syntax is
> not useful, the feval syntax should be used. But how? feval(A,2,3)
> does not work, neither does feval(A(2,3)). Can anyone help?
>
> Thx!
>
> Adi
>



I guess I don't understand. I tried this and it worked:

a{2,3} = magic(6)
a{2,3}([1 3],[ 2 5])

ans =

1 19
9 27

Otherwise, you might need to call the subsref function directly (which
can be a bit of a pain).

--Loren
Adi

2005-12-13, 4:17 am

Thx 4 the help guys! You solved my problem!

Aditya
Adi

2005-12-13, 4:17 am

Thx 4 the help guys! You solved my problem!

Adi
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com