''Too many input arguments'', trouble using callback to call my function?
Mostra commenti meno recenti
I'm making a GUI piano so that when a key is pushed it plays a note. I'm not very good with user defined functions and can't get mine to work.
This is my code for my GUI
pfig=figure('position',[500 150 1000 500 ] )
pbutton2=uicontrol('style','pushbutton',...
'position',[175 20 75 400],... %separate keys by 75
'callback',@sound_a)
and this is my function
function sounda
Fs=8000; %sample rate ranging from 1000 to 384000 in Hz.default is 8192 higher number=higher quality audio.
Ts=1/Fs; %average number of samples obtained per second is 1/t
t=[0:Ts:.3];% durration of play time. 0- how many seconds in increments of ts. shortening time streches out wave resulting in lower sound. .5 = octave down. *2 = octave up
fc=261; %Frequency of middle c is 261 aprx
c=sin(2*pi*fc*t); %the graph of a note. f_a is the hurtz and t is the durration. simple sine wave similar to a tuning fork
sound(c,Fs);
end
the function file name is sound_a. What is wrong with the function?
thanks
Risposta accettata
Più risposte (1)
Walter Roberson
il 15 Apr 2018
1 voto
Callbacks must always accept at least two parameters. MATLAB automatically supplies the handle of the object that it is the callback for as the first parameter, and automatically passes information about the details of the callback as the second parameter.
Therefore you callback must be prepared to accept a minimum of two parameters. It is not required to use the parameters, but it must accept them.
Categorie
Scopri di più su Develop Apps Using App Designer in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!