Imposing a sine wave on line graph

3 vues (au cours des 30 derniers jours)
Joseph Pembamoto
Joseph Pembamoto le 8 Mai 2023
Modifié(e) : Vinayak Gupta le 31 Mai 2023
I am trying to impose a sine wave on a straight line graph and I want it to look like a sine wave with a rotated axis such that if I rotate the image I should see a sine wave and not some squint wave.
I am currently getting this (the squited wave which I don't want):
Here is my code:
clear
clc
close
x = linspace(0, 2*pi, 20);
y_ideal = 3*x;
a = 0.3;
x_ = linspace(0, 5*2*pi, 1000);
imposeFCN = a.*sin(x_*6);
rotated_by = -atan(3);
x_r = x_*cos(rotated_by)+ imposeFCN*sin(rotated_by);
y_r = -x_*sin(rotated_by) + imposeFCN*cos(rotated_by);
plot(x, y_ideal, x_r, y_r)
xlabel("x-axis")
ylabel("y-axis")
xlim([-pi 2*pi])
Thank you in advance
  1 commentaire
VBBV
VBBV le 8 Mai 2023
Read help on rotate function
https://in.mathworks.com/help/matlab/ref/rotate.html

Connectez-vous pour commenter.

Réponses (1)

Vinayak Gupta
Vinayak Gupta le 29 Mai 2023
Modifié(e) : Vinayak Gupta le 31 Mai 2023
Hi Joseph,
I just went through your code, and it is actually correct. A simplified version of mine is attached here.
x = linspace(0,10*pi,1000);
y = 0.3*sin(x*6);
r = 3;
theta = atan(r);
x_r = x*cos(theta)-y*sin(theta);
y_r = x*sin(theta)+y*cos(theta);
plot(x,r*x,x_r,y_r);
xlim([-pi/2 pi/2])
ylim([0 pi])
As you can see I added a ylim with same values as the xlim. The reason your line looks squint is not that its plotted incorrectly, but your axis are non uniform. I have used ylim, but you can also use "daspect" or "axis equal" to get expected results.
Refer to the following to get more information about "daspect" :
Refer to the following to get more information about the usage of "axis" :

Catégories

En savoir plus sur 3-D Scene Control dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by