I need help plotting points with * symbol at intervals equal to Ts = 1/fs = 1/7s (Here is my code)?
Show older comments
Question: Simulate the sampling of this waveform at fs = 7 Hz by plotting a * symbol at intervals
equal to Ts = 1/fs = 1/7 s.
Hint: Could use a for-loop to generate the sample time, Ts, insert it into the equation
for the 5-Hz sine wave, and plot the resulting point.
Code:
clear all;
close all;
clc;
%hwk1_NotLab_Problem1.8.m
f = 5; % Fundamental Frequency in Hz
N = 1000; % Length of array
T_T = 1; % Total Time
Ts = T_T/N;
t = 0:Ts:T_T; % Time vector
x = sin(2*pi*f*t); % 1s of 5-Hz sine wave in 1000 point array
figure;
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('1s of 5-Hz sine wave in 1000 point array');
grid on
Accepted Answer
More Answers (2)
to plot with * symbol, add it to the plot command, e.g.
plot(1:10,rand(10,1),'*')
if you still need a line, add a line style:
plot(1:10,rand(10,1),'-*')
Meet
on 9 Feb 2023
Hi,
Based on the code that you have provided, the sampling rate can be set by changing the value of f to 7. You can add * markers in the plot by passing an additional argument for ‘Marker’ in the plot function.
Please refer the below modified code:
clear all;
close all;
clc;
%hwk1_NotLab_Problem1.8.m
%%
f = 7; % Fundamental Frequency in Hz
N = 1000; % Length of array
T_T = 1; % Total Time
Ts = T_T/N;
t = 0:Ts:T_T; % Time vector
x = sin(2*pi*f*t); % 1s of 7-Hz sine wave in 1000 point array
%%
figure;
plot(t,x,Color="r",Marker="*",MarkerEdgeColor="blue");
xlabel('Time');
ylabel('Amplitude');
title('1s of 7-Hz sine wave in 1000 point array');
grid on;
The generated plot will be as follows:

Categories
Find more on Title in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

