Trying to graph a certain number of periods of a sine function
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Voss
2022 年 12 月 9 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graph and Network Algorithms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
