How can the individual samples be visable in the plot

조회 수: 1 (최근 30일)
Yian Chen
Yian Chen 2021년 9월 26일
편집: Image Analyst 2021년 9월 26일
Like sin(2*pi*100*t) and t is between 0-0.5S, how could there be 25 samples?

채택된 답변

Image Analyst
Image Analyst 2021년 9월 26일
OK, I have a second answer. Maybe your "S" is not a value when you say 0.5S. Maybe "S" really means " seconds". In that case, try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
fprintf('Beginning to run %s.m ...\n', mfilename)
% Like sin(2*pi*100*t) and t is between 0-0.5S, how could there be 25 samples?
numSamples = 25;
t = linspace(0, 0.5, numSamples);
y = sin(2 * pi * 100 * t);
plot(t, y, 'b.-', 'LineWidth', 3, 'MarkerSize', 40);
grid on;
title('y = sin(2 * pi * 100 * t)', 'FontSize', 18);
xlabel('time in seconds', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
g = gcf;
g.WindowState = 'maximized'
fprintf('Done running %s.m.\n', mfilename)
  댓글 수: 2
Yian Chen
Yian Chen 2021년 9월 26일
Hi, thanks for your answer, and s do mean second, if I want my samples defined from 0 to 0.5s but does not include 0.5s, how can I make it?
Image Analyst
Image Analyst 2021년 9월 26일
편집: Image Analyst 2021년 9월 26일
Just change to
t = linspace(0, 0.49999999999, numSamples);
or you can set the range of x in the plot with xlim(), like to see from 0 to 0.4, use
xlim([0, 0.4]);

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

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 9월 26일
Here, try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
fprintf('Beginning to run %s.m ...\n', mfilename)
% Like sin(2*pi*100*t) and t is between 0-0.5S, how could there be 25 samples?
S = 100; % Whatever S is (we don't know because you didn't specify)
numSamples = 25;
t = linspace(0, 0.5 * S, numSamples);
y = sin(2 * pi * 100 * t);
subplot(2, 1, 1)
plot(t, y, 'b.-', 'LineWidth', 3, 'MarkerSize', 30);
grid on;
title('y = sin(2 * pi * 100 * t) with 25 samples (it is badly aliased)', 'FontSize', 18);
xlabel('t', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
% We have bad aliasing. Let's see what it looks like without aliasing.
numSamples = 2000;
t2000 = linspace(0, 0.5 * S, numSamples);
y2000 = sin(2 * pi * 100 * t2000);
subplot(2, 1, 2)
plot(t2000, y2000, 'r.-', 'LineWidth', 1);
grid on;
title('y = sin(2 * pi * 100 * t) with 2000 samples', 'FontSize', 18);
xlabel('t', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
g = gcf;
g.WindowState = 'maximized'
fprintf('Done running %s.m.\n', mfilename)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by