Values not populating in table for variable

26 visualizaciones (últimos 30 días)
Robert Demyanovich
Robert Demyanovich el 16 de Oct. de 2025 a las 17:12
Editada: Walter Roberson el 16 de Oct. de 2025 a las 19:16
I have the following code:
clc
clear all
close all
%define some initial variables
theta = pi/4;
R = 0.0006;
w = 1.318*R;
format longg
%calculate the vector length, p, to the edge of the ellipse
phi=0:0.01:2*pi;
p = (w*sin(theta)^2*cos(phi)+sqrt(R^2*sin(phi).^2+R^2*sin(theta)^2*cos(phi).^2-w^2*sin(theta)^2*sin(phi).^2))/(sin(phi).^2+sin(theta)^2*cos(phi).^2);
x = p.*cos(phi);
y = p.*sin(phi);
When I run this and look at the results in Workspace, the tables holding the values of x and y each have 629 columns with values. However, the table holding the values of p only has one column with one value.
It looks like Matlab is populating the x and y table using only the one value of p and then multiplying it by looping phi to yield the 629 entries. What I need is for Matlab to change "p" with each value of phi and then calculate the corresponding values of x and y. How do I get Matlab to calculate all of the values of p based on the preceding line of code which is:
phi=0:0.01:2*pi;

Respuestas (1)

Dyuman Joshi
Dyuman Joshi el 16 de Oct. de 2025 a las 17:24
%clc
%clear all
%close all
%define some initial variables
theta = pi/4;
R = 0.0006;
w = 1.318*R;
format longg
%calculate the vector length, p, to the edge of the ellipse
phi=0:0.01:2*pi;
There's a element-wise dot symbol missing between the numerator and denominator division sign/operator (scroll to right) -
% v
p = (w*sin(theta)^2*cos(phi)+sqrt(R^2*sin(phi).^2+R^2*sin(theta)^2*cos(phi).^2-w^2*sin(theta)^2*sin(phi).^2))./(sin(phi).^2+sin(theta)^2*cos(phi).^2);
x = p.*cos(phi);
y = p.*sin(phi);
whos
Name Size Bytes Class Attributes R 1x1 8 double p 1x629 5032 double phi 1x629 5032 double theta 1x1 8 double w 1x1 8 double x 1x629 5032 double y 1x629 5032 double
Now as you can see, p (along with x and y) is also same size as phi (1x629).

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by