Error using sound (line 76) Index exceeds matrix dimensions.
Show older comments
Below is the code that I am trying to run, however I cant seem to sound my "song" even though I could sound my "test". The only difference between the 2 of them is just the difference of line 4, which can be played.
Can someone enlighten me on this issue? Thank you.
A=sin(2*pi*440*(0:0.000125:0.5));
B=sin(2*pi*493.88*(0:0.000125:0.5));
B1 = sin(2*pi*493.88*(0:0.000125:1));
B2=sin(2*pi*493.88*(0:0.000125:2));
C5=sin(2*pi*523.25*(0:0.000125:0.5));
C1=sin(2*pi*523.25*(0:0.000125:1));
D=sin(2*pi*293.66*(0:0.000125:0.5));
D5=sin(2*pi*587.33*(0:0.000125:0.5));
E5=sin(2*pi*659.2*(0:0.000125:0.5));
El=sin(2*pi*659.25*(0:0.000125:1));
G=sin(2*pi*392.00*(0:0.000125:0.5));
G1=sin(2*pi*392.00*(0:0.000125:1));
As = sin(2*pi*466.16*(0:0.000125:0.5));
pause=sin(2*pi*0*(0:0.000125:0.01));
line1=[D,G,A,B1,B1,pause,B,As,B,G1,G1,pause];
line2=[G,A,B,C1,El,pause,E5,D5,C5,B2,pause];
line3=[G,A,B,C1,El,pause,E5,D5,C5,B,G1,pause];
line4=[G,A,B1,pause,C5,A,pause,A,B,G1];
song=[line1,line2,line3,line4];
test=[line1,line2,line3];
sound(song);
Answers (1)
Walter Roberson
on 25 Jan 2017
1 vote
4 Comments
Star Strider
on 25 Jan 2017
After you do everything on the linked page, it’s necessary to close and then restart MATLAB (at least on Windows systems).
Walter Roberson
on 25 Jan 2017
Step 3 says to close MATLAB ;-)
Star Strider
on 25 Jan 2017
I missed that! (I was concentrating on getting the file in the correct directory.)
Lin Jie
on 4 Mar 2017
truly great answer and helps me a lot!
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!