MATLAB Answers

Cannot get points on a plot to show

2 views (last 30 days)
I am trying to plot N versus error and nothing shows up in the plot.
I am not getting any errors but its not plotting anything.
Any advice is appreciated, code is below.
Thanks
clear,clc;
w = pi/2;
t = 0:0.01:4;
x = t.*(0<t&t<2)+(4-t).*(2<=t&t<=4);
for N = 1:10
Ao = 1;
xhat=Ao;
for q = 1:N
xhat = xhat+(-2./((q.^(2).*pi.^(2)+N))*exp(1i*q*w*t))
xhat = xhat+(-2./((-q).^(2).*pi.^(2)+N)*exp(1i*(-q)*w*t))
end
error(N) = mean((x-xhat).^2);
plot(N,error(N));
hold all
end

  0 Comments

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 29 Jan 2020
Edited: Fangjun Jiang on 29 Jan 2020
You are plotting one point at a time, use
plot(N,error(N),'+')
or at the end,
plot(1:10,error)

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags


Translated by