Trying to graph a certain number of periods of a sine function
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Voss
on 9 Dec 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 Comments
See Also
Categories
Find more on Graph and Network Algorithms 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!