sound function with sprintf

3 views (last 30 days)
Barry Bardsley
Barry Bardsley on 25 Jan 2023
Commented: Barry Bardsley on 25 Jan 2023
Hi all
Its been a number of years since I used MATLAB and some of the code I once used doesn't seem to work as I once used. I know MATLAB got rid rid of wavplay so we should now be using sound but I seem to have hit a snag when it comes to running it through a for loop.
I have a bunch of variables that are my sound files which play perfectly fine when I run them through a standard command ie sound(condition1,44100)
However, when I try to run a for loop like this below, I have an error saying "Audio data must be real and floating point".
n = 6;
for i = 1:n;
sound(sprintf('condition%d',i))
pause(1)
end
In previous version, I notice sprintf would ouput without the apostrophe, whereas now it is (ie 'conditon1' as oppose condition1)
Any help would be gratefully received.
Barry
  3 Comments
Walter Roberson
Walter Roberson on 25 Jan 2023
You can see from http://matlab.izmiran.ru/help/techdoc/ref/wavplay.html that character vectors were never valid input for wavplay()
Barry Bardsley
Barry Bardsley on 25 Jan 2023
Stephen23, thanks for coming back to me on this, it really is much appreciated. I will get on the case, and have started following the guidance in the links.
Thanks again.
Barry

Sign in to comment.

Answers (0)

Categories

Find more on Audio I/O and Waveform Generation 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!