Plotting Sin Curve with limitations

3 次查看(过去 30 天)
Garen Douzian
Garen Douzian 2015-5-17
编辑: dpb 2015-5-17
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?

回答(1 个)

dpb
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.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by