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

Stephen23
Stephen23 2023년 1월 25일
편집: Stephen23 2023년 1월 25일
"In previous version, I notice sprintf would ouput without the apostrophe, whereas now it is (ie 'conditon1' as oppose condition1)"
SPRINTF has never added extra single quotes onto text data (unless they are in the text itself). You are confusing the data content with how data are displayed. A few years back (around 2016?) MATLAB changed how it displayed character vectors (to show them with single quotes), but this is unrelated to SPRINTF() and makes absolutely no difference to the content of the character vector. The displaying using single quotes is explained here:
"...some of the code I once used doesn't seem to work as I once used"
A quick perusal of the help going back to 2009 shows SOUND() has never accepted a character vector input.
"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)"
Then the actual source of your error is bad data design, specifically forcing pseudo-indices into variable names:
The simple solution is to use actual indexing, just like MATLAB is designed for and just as the documentation shows:
"Any help would be gratefully received. "
Never force meta-data into variable names.
Walter Roberson
Walter Roberson 2023년 1월 25일
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 2023년 1월 25일
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

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

질문:

2023년 1월 25일

댓글:

2023년 1월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by