How can the individual samples be visable in the plot

조회 수: 3(최근 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
Image Analyst
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]);

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

추가 답변(2개)

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)

VBBV
VBBV 2021년 9월 26일
S = linspace(0,0.5,25)
ans = 1×25
0 0.0208 0.0417 0.0625 0.0833 0.1042 0.1250 0.1458 0.1667 0.1875 0.2083 0.2292 0.2500 0.2708 0.2917 0.3125 0.3333 0.3542 0.3750 0.3958 0.4167 0.4375 0.4583 0.4792 0.5000
  댓글 수: 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?

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by