Imposing a sine wave on line graph

3 visualizaciones (últimos 30 días)
Joseph Pembamoto
Joseph Pembamoto el 8 de Mayo de 2023
Editada: Vinayak Gupta el 31 de Mayo de 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 comentario
VBBV
VBBV el 8 de Mayo de 2023
Read help on rotate function
https://in.mathworks.com/help/matlab/ref/rotate.html

Iniciar sesión para comentar.

Respuestas (1)

Vinayak Gupta
Vinayak Gupta el 29 de Mayo de 2023
Editada: Vinayak Gupta el 31 de Mayo de 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" :

Categorías

Más información sobre 3-D Scene Control en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by