Imposing a sine wave on line graph
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Vinayak Gupta
2023-5-29
编辑:Vinayak Gupta
2023-5-31
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" :
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Scene Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!