MATLAB Answers

sound will not play Mac Matlab 2018b

12 views (last 30 days)
Hi there, I am working through a brilliant Udeny course in Matlab and am currently working on generating a sound but am finding that this session does not work, even though I have written exactly as specified (I think!)
frequencies = 5000; % Hz
duration = 1; % duration of the sound
amplitude = 1; % loudness
fs = 44100; % Sampling rate
T = 1 / fs ; % Time sampling period
t = 0:T:duration; % time vector
signal = amplitude * cos(2 * pi * frequencies * t);
sound(signal, fs)
Can anyone tell me where I'm going wrong please?

  9 Comments

Show 6 older comments
Walter Roberson
Walter Roberson on 19 Feb 2020
I suspect that you still have another sound.m
which -all sound
Walter Roberson
Walter Roberson on 19 Feb 2020
MATLAB Online is at
http://matlab.mathworks.com
Not all licenses have access to that, but current student licences do.
Tracey Rochester
Tracey Rochester on 20 Feb 2020
Thank you everyone, I trashed my file, and then emptied it, and the sound is now playing.

Sign in to comment.

Accepted Answer

Ajay Pattassery
Ajay Pattassery on 20 Feb 2020
Edited: Ajay Pattassery on 20 Feb 2020
The issue is most likey due to having multiple user-defined sound.m files.
Replace sound(signal, fs) with the following code
player = audioplayer(signal,fs);
play(player)
If it is playing for the above code, execute the following line
which -all sound
If it returns more than one sound.m location, rename all the sound.m files in location other than MATLAB builtin path which ends with toolbox\matlab\audiovideo\sound.m

  0 Comments

Sign in to comment.

More Answers (1)

Tracey Rochester
Tracey Rochester on 19 Feb 2020
By the way, I'm running MATLAB R2018b, on a Mac, OS 10.14.6 Mojave...

  0 Comments

Sign in to comment.

Sign in to answer this question.