How to evaluate an array of function handles at different points

I have a cell array of 3 functions handles
phi={@ (x,y) 1-x-y,@ (x,y) x,@(x,y) y}
I need to evaluate it at 4 different points (0,0) (1,0) (0,1) and (1/3 1/3)
q=[0 1 0 1/3;0 0 1 1/3]
to create an 3x4 array of values where each row represents a function at four different points
How do I do it?
Thanks

 Respuesta aceptada

This is a case where a for loop would probably be fastest. You could instead use
cell2mat( arrayfun( @(x,y) [phi{1}(x,y), phi{2}(x,y), phi{3}(x,y), phi{4}(x,y)], q(1,:).', q(2,:).', 'Uniform', 0 ) )
but arrayfun is going to be slower than a for loop.

3 comentarios

I am sorry, but I do not understand your response. I only have 3 function handles, not 4 I have 4 point (x,y coordinates) not 2
cell2mat( arrayfun( @(x,y) [phi{1}(x,y), phi{2}(x,y), phi{3}(x,y)], q(1,:).', q(2,:).', 'Uniform', 0 ) )
Thank you. That was very helpful

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Mzo. de 2017

Comentada:

el 6 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by