Why is my plot shaking but not plotting the noise?

조회 수: 14 (최근 30일)
Jorge Arturo Clares Pastrana
Jorge Arturo Clares Pastrana 2022년 2월 16일
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

채택된 답변

Arif Hoq
Arif Hoq 2022년 2월 16일
편집: Arif Hoq 2022년 2월 16일
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
Arif Hoq
Arif Hoq 2022년 2월 16일
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)');
Jorge Arturo Clares Pastrana
Jorge Arturo Clares Pastrana 2022년 2월 16일
thanks, its exactly what i was looking for

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by