Loading .m file that is a String argument

4 ビュー (過去 30 日間)
LBZ27
LBZ27 2017 年 4 月 26 日
編集済み: Stephen23 2017 年 4 月 26 日
I am trying to write a small program that repeats a sound N times. The sound files are already stored in their respective .m files. In my function, I have three input arguments:
in = String name of the .m file I want to play
N = number of repetitions
p = pause in seconds between each repetition
However, with my code, I am getting an error message that reads "Audio data must be real and floating point." I am confused, because I can play the sound file by writing commands in the command window just fine.
function out = repeatPause(in, N, p)
load(in);
for j = 1 : N;
sound(in);
pause(p);
end
And in the command prompt, to call this function I write:
repeatPause('sample.mat', 3, 5)
What could be the issue here? Is it because the String file name is not being passed through to the function when I call it?
  1 件のコメント
Stephen23
Stephen23 2017 年 4 月 26 日
編集済み: Stephen23 2017 年 4 月 26 日
Your code would be much mroe reliable if you load into a structure:
S = load(in);
and then access the data inside the structure S. Then you would avoid all of these problems.

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2017 年 4 月 26 日
You have to replace sound(in) in with the variable in the sample.mat file. You are loading the file and using sound on the filename instead of variable.

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by