Plotting Sin Curve with limitations
3 ビュー (過去 30 日間)
古いコメントを表示
Hi, I'm attempting to graph 2 sin curves, however one of them is limited to always being at least 30 pixels below the other, as can be seen in this image:

The third graph labelled "Spring Length" is just the top graph - second graph. I was contemplating using a for loop to execute this but i wasn't sure how. so far i have:
theta=0:1:359
y=485+sind(theta)
z=285+sind(theta-90)
if y-z<30
z=y-30
end
plot(theta,y)
plot(theta,z)
however this doesnt seem to work. Any suggestions?
0 件のコメント
回答 (1 件)
dpb
2015 年 5 月 17 日
編集済み: dpb
2015 年 5 月 17 日
As written your two sine terms have an amplitude of unity and an offset. Consequently, your plot is going to be basically three straight lines. To see this, set
ylim([480 490])
temporarily on your figure and you'll see the one sine wave clearly.
Use the power of Matlab; no loops needed! :)
Try something like
theta=[0:359].';
y=485+200*sind(theta);
z=285+200*sind(theta-90);
z=min(z,y-30);
plot(theta,[y z y-z])
I just approximated the amplitude value of 200; you'll want to adjust per your actual conditions but the above gives the desired type of plot.
NB: the .' on theta to create column vectors for the responses so can concatenate them by column for plot
ADDENDUM BTW, if I use an offset of 430 for the upper and an amplitude of 150 for both I get a plot that looks very similar to your figure.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!