Need help about function

3 ビュー (過去 30 日間)
moonman
moonman 2011 年 9 月 19 日
I have written this function for piano
function tone=note(keynum,dur) % %This function produces sinusoidal waveform corresponding to given piano %key number %tone=output sinusoidal waveform %keynum= The piano keyboard number %dur= The duration in seconds of output note fs=8000; tt=0:(1/fs):dur; freq = 440 (2^((keynum-49)/12)); tone=sin(2*pi*freq(0:0.000125:1));
Now If i use soundsc(tone,fs) command in the code of this function then every thing is ok but the book says
"You can play the output of this function using the soundsc() function in Matlab. DO NOTcall the sound fucntion within the M-file.
Plz help me how to go about this. when i write note(12,3) in matlab it is ok but when i write soundsc(tone,fs) in matlab after this it gives error

採用された回答

Wayne King
Wayne King 2011 年 9 月 19 日
How are you calling the function, note(), at the command line?
You should call it as:
tone = note(12,3);
Then there will be a variable in your workspace named tone and you can execute
soundsc(tone,fs)
If you call it as
note(12,3)
then your output appears as ans
Wayne
  1 件のコメント
moonman
moonman 2011 年 9 月 19 日
Thanks a lot King, u r true Guru of Matlab

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by