Plotting Sin Curve with limitations
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
dpb
le 17 Mai 2015
Modifié(e) : dpb
le 17 Mai 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.
0 commentaires
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!