Trying to graph a certain number of periods of a sine function
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm developing a GUI that allows the user to input the specifications of a wave function (amplitude, etc). I have set it up to graph the function and its two derivatives on axes within the GUI. I would like the user to be able to specify the number of periods for each graph -- not the upper and lower bounds, but the total number of periods and then ideally the graph would adjust the upper and lower bounds to display the correct number of periods for each graph. Is this possible/ how would I go about adding this?
0 commentaires
Réponses (1)
Voss
le 9 Déc 2022
A= 2; % amplitude = 2
f = 10; % frequency = 10 Hz (a.k.a. 10 cycles per second)
N = 4; % number of periods = 4 (a.k.a. 4 cycles)
t_max = N/f; % N cycles / f cycles per second = N/f seconds <- time required for N cycles at frequency f
t = linspace(0,t_max,1000);
x = A*sin(2*pi*f*t);
plot(t,x)
You can use t = 0 as the left x-limit, then the right x-limit is t_max = N/f as given above. Set the x-limits in your GUI like:
set(ax,'XLim',[0 t_max])
where ax is your axes.
0 commentaires
Voir également
Catégories
En savoir plus sur Graph and Network Algorithms 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!
