Error: Data must be numeric, datetime, duration, categorical, or an array convertible to double.

조회 수: 19 (최근 30일)
Hello everyone,
I am trying to plot a function that has two different variables: theta and phi.
Theta = -pi/2:0.1:pi/2
Phi = Specific Values at 0 and pi/2
I have an error that says:
"Error: Data must be numeric, datetime, duration, categorical, or an array convertible to double."
I've tried looking up this error on different discussions. However, I wasn't able to find anything that helped with my specific scenario.
I have tried different methods and approaches: Using "symbolic variables", fimplicit function, fplot function, etc. However, I got different errors everytime I tried a different approach.
I attached my code for reference:
Plotting_Theta_Phi_Function.m

채택된 답변

Voss
Voss 2024년 7월 7일
tic
close all; clc;
% Declaring Theta and Phi Variables
theta = 0:0.1:pi/2;
% Phi Values
phi_E_Plane = 0;
phi_H_Plane = pi/2;
phi = [phi_E_Plane, phi_H_Plane];
% Declaring x and y variables as theta and phi
x = sin(phi);
y = cos(theta);
% Function Z is a combination of x and y
Z = @(x,y) x.^2.*y + y.^2.*x;
% Calculating E-Plane and H-Plane "values"
E_Plane = Z(theta,phi(1));
H_Plane = Z(theta,phi(2));
% Plotting E-Plane = Theta Range at phi = 0
plot(theta,E_Plane);
% Holding on to put the H-Plane on the same grid as the E-Plane
hold on;
% Plotting H-Plane = Theta Range at phi = pi/2
plot(theta,H_Plane);
% Placing a grid on the graph
grid on;
% Title, Axes, and Legends
title('E-Plane (dB) and H-Plane (dB) versus Theta (Radians)');
legend({'E-Plane','H-Plane'},'Location','northwest');
xlabel('Theta (Radians)');
ylabel('Magnitude (dB)');
toc
Elapsed time is 0.343450 seconds.
  댓글 수: 5
Ammar
Ammar 2024년 7월 8일
Hi Voss and Walter,
Thank you for providing this guidance. As far as everything else (plotting, setting the step size for theta, etc), is that meant to be done within the function or outside?
I understand how to "execute the function" F(theta,phi) value. However, I'm trying to extract and then plot specific values for "F".
Would I need to write "seperate" functions for each "task" I'm trying to do: plotting, setting grid size, axes limits, etc? Or can I just write everything into one function?
theta = -pi/2:0.01:pi/2;
phi = [0 pi/2];
E_Plane = F(theta,0);
H_Plane = F(theta,pi/2)
% Then plotting the E-plane and H-plane
plot(theta,E_Plane)
hold on;
plot(theta,H_Plane)
% Other Axis and Grid Settings....
% etc...
Voss
Voss 2024년 7월 8일
The function F (or getZ as I called it) would only calculate Z given theta and phi. Everything else would be outside the function, either in a script or in separate functions if you prefer.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2024년 7월 7일
% Declaring Theta and Phi Variables
theta = 0:0.1:pi/2;
% Phi Values
phi_E_Plane = 0;
phi_H_Plane = pi/2;
% Declaring x and y variables as theta and phi
x = @(phi)sin(phi);
y = @(theta)cos(theta);
% Declaring the function Z as a function of theta and phi
F = @(theta,phi)x(phi).^2.*y(theta) + y(theta).^2.*x(phi);
% Calculating E-Plane and H-Plane "values"
E_Plane = F(theta,phi_E_Plane);
H_Plane = F(theta,phi_H_Plane);
% Plotting E-Plane = Theta Range at phi = 0
plot(theta,E_Plane);
% Holding on to put the H-Plane on the same grid as the E-Plane
hold on;
% Plotting H-Plane = Theta Range at phi = pi/2
plot(theta,H_Plane);
% Placing a grid on the graph
grid on;
% Title, Axes, and Legends
title('E-Plane (dB) and H-Plane (dB) versus Theta (Radians)');
legend({'E-Plane','H-Plane'},'Location','northwest');
xlabel('Theta (Radians)');
ylabel('Magnitude (dB)');
  댓글 수: 1
Ammar
Ammar 2024년 7월 7일
편집: Walter Roberson 2024년 7월 8일
Hello Torsten,
Thank you for the quick response.
My main concern is that my function "Z" is going to grow larger and larger. In other words, its going to be comprised of many different variables and functions that include phi and theta. At that point, I won't be able to "directly" write out the function for "Z".
For example:
x = sin(theta)
y = cos(phi)
a = sin(2*theta)
Y = (a).^2 + (y).^2 + (x).^2
R = 2*Y + (a).^2
Z = (R).^2 + (Y).^2
That's why I used the function "F" to say:
F = @(theta,phi) (Z)
Is there another method to plot "Z" for the specific cases that I have? Thanks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by