Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
Rahul
Rahul am 20 Jun. 2023
Kommentiert: David Goodmanson am 20 Jun. 2023
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 Kommentar
David Goodmanson
David Goodmanson am 20 Jun. 2023
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Naman
Naman am 20 Jun. 2023
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

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by