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