How to plot angle (in radians) versus phase shift?

8 次查看(过去 30 天)
Hi,
I want a profile with phase angle plotted against angle in radians.
Presently I have a code with phase angle plotted against a linear distance which is as below.
Need your valuable advice how to do the necessary changes in this code.
Also I need to determine its slope.
Sincerely,
rc
clc;
clear;
phi_1 = [0.1724*pi 0.1472*pi 2.18*pi 2.25*pi 4*pi 3.588*pi 1.012*pi 4.112*pi 4.31*pi 4.25*pi 0.832*pi];
x1 = linspace(0,1,11);
coefficients1=polyfit(x1,phi_1,1);
slope1=coefficients1(1);
intercept1=coefficients1(2);
figure(1)
hold on
plot(x1,phi_1,'o')
plot([0 1],intercept1 + slope1*[0 1])
  1 个评论
David Goodmanson
David Goodmanson 2023-6-20
Hi Rahul,
you can shorten up the code by eliminating the slope and intercept calculations and plotting the line with
plot([0 1],polyval(coefficients1,[0 1])).
It's not possible to say anything about plotting using angle without knowing the lower and upper limits of the angle. Anyway, any kind of straight line fit to this data looks pretty dubious.

请先登录,再进行评论。

采纳的回答

Naman
Naman 2023-6-20
Hi Rahul,
To plot phase angle against angle in radians instead of linear distance, you will need to replace the x-axis values with angle values. Assuming you want to plot angle values from 0 to 2*pi, you can generate them using the linspace function and modify the plot accordingly. Here's the modified code:
clc;
clear;
phi_1 = [0.1724*pi 0.1472*pi 2.18*pi 2.25*pi 4*pi 3.588*pi 1.012*pi 4.112*pi 4.31*pi 4.25*pi 0.832*pi];
theta = linspace(0, 2*pi, numel(phi_1)); % generate angle values
coefficients1 = polyfit(theta, phi_1, 1);
slope1 = coefficients1(1);
intercept1 = coefficients1(2);
figure(1)
hold on
plot(theta, phi_1, 'o') % plot phase angle against angle in radians
plot([0 2*pi], intercept1 + slope1 * [0 2*pi]) % plot linear fit
xlabel('Angle (radians)') % update x-axis label
ylabel('Phase angle') % update y-axis label

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by