Plotting a sinusoidal wave

조회 수: 51 (최근 30일)
Mat Smith
Mat Smith 2016년 4월 24일
댓글: Image Analyst 2020년 11월 9일
Hello,
I'm not sure how to go about write a function for a sinusoid that oscillates between 0 and 0.1 with a period of 1 second. The sinusoid should be sampled at 2ms and plotted for the first 10 seconds. Thank you in advance.

채택된 답변

Image Analyst
Image Analyst 2016년 4월 24일
Try this:
% Make a sinusoid that oscillates between 0 and 0.1 with a period of 1 second.
% The sinusoid should be sampled at 2 ms and plotted for the first 10 seconds.
amplitude = 0.1;
period = 1.0;
% Time samples go from 0 to 10 seconds.
% Have 5000 of them so that the spacing is 2 milliseconds.
t = linspace(0, 10, 5000);
% Create y
y = amplitude * sin(2 * pi * t / period);
plot(t, y, 'b-', 'LineWidth', 2);
xlabel('t', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
grid on;
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
  댓글 수: 3
EDEN
EDEN 2020년 11월 9일
in this graph, how can i show the x-axis of this graph, i mean the line at zero level.
Image Analyst
Image Analyst 2020년 11월 9일
Two ways, depending on exactly how you'd like it to appear. If you want the axis (including tick marks) there at y = 0, you can do this:
plot(-10:10)
grid on;
ax = gca
ax.XAxisLocation = 'origin';
or, if you still want the tick marks at the bottom you can just use yline(0);
plot(-10:10)
grid on;
yline(0, 'LineWidth', 3, 'Color', 'k');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by