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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by