"Too many output arguments" for non-outputting function
Show older comments
Matlab novice here; my previous programming experience is mostly with C++ and Java. I have a college assignment to use Matlab to play some music, and I've hit a snag in a function I'm trying to write to speed things up. I composed the alto staff of the first line of the song, but when I went to test-run the file to see if I was on the right track, I got an error message that I had too many output arguments... for a function that outputs no arguments (a void function in C++ parlance).
My current code (less the introductory comments):
% Misc Global Variables
sf = 2000; % sampling frequency
% Note frequencies (Hz) - GLOBAL CONSTANTS
% middleC = 261.63; % middle C included as reference point; commented out
% b/c highest note in refrain is an A flat
D = 293.66;
E = 329.63;
F = 349.23;
G = 392.00;
Aflat = 415.30; % relevant staff is marked with a flat on the A space
% Song playback
note(G, 0.1); % I
note(G, 0.1); % was
note(G, 0.2); % cho-
note(F, 0.1); % -sen
note(E, 0.1); % by
note(F, 0.2); % heav-
note(D, 0.3); % -en
function note(pitch, duration)
% NOTE Local function that outputs a note for playback based on an input
% pitch (i.e. frequency) and duration
t = 1:1/sf:duration;
n = sin(2 * pi * pitch * t);
sound(n, sf);
end
The error message is on line 41, the line that says t = 1:1/sf:duration;. The intent of the function is just to save me having to type sound(note(pitch, duration), sf); a gazillion times by letting me just type note(pitch, duration); to get playback. But it doesn't work even if I move sound() out of the note() function.
Using Matlab R2020b.
Accepted Answer
More Answers (0)
Categories
Find more on Measurements and Spatial Audio in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!