Why is my plot shaking but not plotting the noise?

clear;
clc;
for x = 0:(pi/200):(2*pi)
e = rand;
y = x*sin(x)+(0.5*e);
x_star = [0:(pi/200):(2*pi)].';
y_star = x_star.*sin(x_star)+0.5*e;
figure(1)
plot(x_star,y_star)
grid on
title('Hw1');
xlabel('x');
ylabel('f(x)');
end

 Accepted Answer

x = 0:pi/200:(2*pi);% does't need
e = rand; % does't need
y = x.*sin(x)+(0.5*e); % does't need
x_star = 0:(pi/200):(2*pi); % x_star and x same
y_star = x_star.*sin(x_star)+0.5*rand(size(x_star)); % adding noise 0.5*rand(size(x)) y_star and y same
figure(1)
plot(x_star,y_star)
grid on
title('Hw1');
xlabel('x');
ylabel('f(x)');

2 Comments

Or simply
x = 0:pi/200:(2*pi);
e = 0.5*rand(size(x)); % noise
y = x.*sin(x)+e;
figure(1)
plot(x,y)
grid on
title('Hw1');
xlabel('x');
ylabel('f(x)');
thanks, its exactly what i was looking for

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!