Using output of a function into the integral2 Function - Unrecognized function or variable

1 次查看(过去 30 天)
Hello,
I'm currently facing an issue with using an output of a function into an integral.
I have attached my code for reference:
P_RAD.m
Unfortunately, for this case, I have to use a function in my code because I need it to plot certain parameters. I understand what the error is saying and why it is saying it. I'm trying to see if there is a workaround for this.
This is the integration I am trying to do: See screenshot attached: P_RAD_Integration.png
The error that I'm facing is shown below.
% Unrecognized function or variable 'U_Rad'.
Error in Patterns (line 200)
P_rad = U_Rad.*sin(theta);

采纳的回答

Walter Roberson
Walter Roberson 2024-7-11
U_Rad is defined only as the nominal output variable of function Cuts.
You call
E_Plane(n) = Cuts(loop_theta, phi_E);
% Specifying the H_Plane cut as an array with theta values and phi_H
H_Plane(n) = Cuts(loop_theta, phi_H);
so the values assigned internally to U_Rad inside the function are transfered to output variables E_Plane and H_Plane
P_rad = U_Rad.*sin(theta);
P_rad_function = matlabFunction(P_rad);
Besides U_Rad being undefined here: you do not have any symbolic variables, so you cannot construct a matlabFunction
What you need is
syms theta phi
P_rad = Cuts(theta,phi).*sin(theta);
P_rad_function = matlabFunction(P_rad, 'Vars', [theta, phi]);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by