Plotting Sin Curve with limitations

1 view (last 30 days)
Garen Douzian
Garen Douzian on 17 May 2015
Edited: dpb on 17 May 2015
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?

Answers (1)

dpb
dpb on 17 May 2015
Edited: dpb on 17 May 2015
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.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!