I can't see the cosine graph. How do I generate the cosine graph using 2^10 samples?
Show older comments
deltat=0.1;
nsamples=2^10;
time=[0 : deltat : deltat*(nsamples-1)];
for i=1: nsamples
ydata(i,:)=[5+10*cos(2*pi*time+pi/6)];
end
figure(1);
plot(time,ydata,'b')
I try to generate the cosine graph with 2^10 samples.
I used 1024 (=2^10) time samples to create the cosine graph.
The time interval is 0.1 seconds.
Could you explain why I have 1024*1024 ydata rather than 1*1024 ydata?
How do I create a cosine graph using time sample data?
Accepted Answer
More Answers (2)
Mitchell Thurston
on 4 Apr 2024
You should be able to just get rid of the for loop,
ydata = 5 + 10*cos(2*pi*time+pi/6)
deltat = 0.001;
nsamples = 2000;
time =[0 : deltat : deltat*(nsamples-1)];
size(time)
% for i = 1:nsamples
% ydata(i,:) = 5 + 10*cos(2*pi*time + pi/6);
% end
ydata = 5 + 10*cos(2*pi*time + pi/6);
size(ydata)
plot(time, ydata), grid on
Categories
Find more on Startup and Shutdown 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!


