Imposing a sine wave on line graph
6 ビュー (過去 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):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1377174/image.png)
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 件のコメント
VBBV
2023 年 5 月 8 日
Read help on rotate function
https://in.mathworks.com/help/matlab/ref/rotate.html
回答 (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!