Put Zero Value randomly in wave function

조회 수: 1 (최근 30일)
Rakan Akmal Musalim
Rakan Akmal Musalim 2022년 3월 19일
답변: Atsushi Ueno 2022년 3월 19일
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');

채택된 답변

Star Strider
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');
.

추가 답변 (1개)

Atsushi Ueno
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');

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by