multiplying two cells array

1 visualización (últimos 30 días)
El Rassy Elissa
El Rassy Elissa el 22 de Mzo. de 2017
Respondida: Steven Lord el 22 de Mzo. de 2017
hiii, I have the problem of multiplying two cells array (present in the same array)and having a function type ; A={@(p) 2./(p+2),@(p)1./p} B=A{1}*A{2};
so I got the error Undefined function 'mtimes' for input arguments of type 'function_handle'. which is the error in B={A{1}*A{2}}; can someone help me to know how to multiply functions present as cells in arrays, in order to use them later for iterations and laplace inverse.

Respuestas (2)

Chad Greene
Chad Greene el 22 de Mzo. de 2017
I think you're looking for cellfun.

Steven Lord
Steven Lord el 22 de Mzo. de 2017
You can't multiply function handles. You can multiply the values you receive by evaluating function handles.
f1 = @sin;
f2 = @cos;
thisWillErrorWhenEvaluated = @(x) f1.*f2;
thisWillWork = @(x) f1(x).*f2(x);
x = 0:0.1:2*pi;
y = thisWillWork(x);
figure
plot(x, y)
thisWillError = thisWillErrorWhenEvaluated(x)
figure
plot(x, thisWillError)
If you run all this code as one piece, you will see only one plot. Only the first plot call will be executed; the code will error when trying to evaluate thisWillErrorWhenEvaluated.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by