Trying to graph a certain number of periods of a sine function

3 visualizaciones (últimos 30 días)
Nathalie
Nathalie el 8 de Dic. de 2022
Respondida: Voss el 9 de Dic. de 2022
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?

Respuestas (1)

Voss
Voss el 9 de Dic. de 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.

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by