Matlab not plotting graph
显示 更早的评论
Here is the code which i m trying to implement and plotting digital high and digtial low signal if value from signal exceeds a certain value but matlab is not plotting second graph ( z with respect to t ) . Any help would be appreciated.
recorder = audiorecorder(22000, 8, 2);
disp('Start speaking.')
recorder.record(20);
startTime = datetime('now');
z=[];
while recorder.isrecording()
pause(0.1);
y = (getaudiodata(recorder));
x=abs(y);
[up1,lo1] = envelope(x,4000,'rms');
t = datetime('now') - startTime;
t = t*24*3600;
%x=smooth(up1,'sgolay');
%pks = findpeaks(up1,'MinPeakDistance',10000);
%up1
if (up1>0.15)
z=[z 1];
else
z=[z 0];
end
subplot(2,1,1)
plot(up1);
drawnow();
subplot(2,1,2)
plot(t,z);
drawnow();
end
disp('End of Recording.');
回答(1 个)
Walter Roberson
2020-2-12
0 个投票
envelope returns a vector. Not all elements of the vector are greater than 0.15 so the if fails, because if is only true if all the items in the array being tested are true. So you always do the else case and append 0 to z. Then when you plot z it is all zero and you do not happen to notice that because the default plot range would put the zeros exactly at the bottom axes where it is easy to overlook.
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!