Put Zero Value randomly in wave function
조회 수: 1 (최근 30일)
이전 댓글 표시
So i have a sin wave function and i want to put zero value number randomly into the wave function. Is that possible and how to ?
%Sine wave
freq=400;
Amp=2;
t_samp=1/8000;
T=0.01;
t=0:t_samp:T;
y=Amp*sin(2*pi*freq*t);
subplot(2,1,1);
plot(t,y)
ylabel ('Amplitude');
xlabel ('Time');
title ('Sine wave');
댓글 수: 0
채택된 답변
Star Strider
2022년 3월 19일
Try something like this —
%Sine wave
freq=400;
Amp=2;
t_samp=1/8000;
T=0.01;
t=0:t_samp:T;
y=Amp*sin(2*pi*freq*t);
y(randi(numel(y))) = 0; % Random Value (Index) = 0
subplot(2,1,1);
plot(t,y)
ylabel ('Amplitude');
xlabel ('Time');
title ('Sine wave');
.
댓글 수: 0
추가 답변 (1개)
Atsushi Ueno
2022년 3월 19일
Yes it is possible. You can put zero value by making random value index of y.
%Sine wave
freq=400;
Amp=2;
t_samp=1/8000;
T=0.01;
t=0:t_samp:T;
y=Amp*sin(2*pi*freq*t);
y(randi([1 numel(y)],1,10)) = 0; % ----- here
subplot(2,1,1);
plot(t,y)
ylabel ('Amplitude');
xlabel ('Time');
title ('Sine wave');
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!