why this message error ?:Array indices must be positive integers or logical values

조회 수: 1 (최근 30일)
Hi,
When i write this little script:
---------------------------------------------------------------------------------------------------------
demo matlab
t = (10:1:200)';
y = sin(2*pi*50*t)
z = y(t-10)
w = y+z
plot(t(1:50),w(1:50))
sound(w,Fs);
-------------------------------------------------------------------------------------------------------
there is a message error: message error: Array indices must be positive integers or logical values.
Howewer,when i write this:
-----------------------------------------------------------------------------------------------------
demo matlab
t = (0:0.001:100)';
y = sin(2*pi*50*t)
plot(t(1:50),y(1:50))
sound(y,Fs);
------------------------------------------------------------------------------------------------------
there is no message error.
Why?
thanks

채택된 답변

Image Analyst
Image Analyst 2018년 9월 30일

추가 답변 (2개)

jérôme TAÏEB
jérôme TAÏEB 2018년 9월 30일

Ok but

demo matlab

 t = (11:1:200)';
 y = sin(2*pi*50*t)

z = y(t-10)

w = y+z

plot(t(1:50),w(1:50))

sound(w,44000);

no longer presents an error message but no sound comes out!

Why ?

  댓글 수: 3
Star Strider
Star Strider 2018년 9월 30일
The sound is there. It is of too short a duration to notice:
signal_duration = (200-11)/44000
signal_duration =
0.00429545454545455
It only lasts for 4.3 milli-seconds!
jérôme TAÏEB
jérôme TAÏEB 2018년 9월 30일
편집: jérôme TAÏEB 2018년 9월 30일
It doesn't work !
Can i have the completely corrected code?

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


Image Analyst
Image Analyst 2018년 9월 30일

See attached sound making demo. It doesn't make your sound but adapt it as needed.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by