error in the code

7 vues (au cours des 30 derniers jours)
Giovanni Scamardo le 9 Avr 2022
Commenté : Jan le 10 Avr 2022
t=linspace(0,2,16000);
sol=sin(2*pi*392*t);
si=sin(2*pi*493.88*t);
la=sin(2*pi*440*t);
soundsc([si; la; sol; la; si; si; si])
I wrote this code but from imsefuenti errors:
Error in soundsc (line 63)
sound(varargin{:});
Error in untitled3 (line 5)
soundsc([si; la; sol; la; si; si; si])
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Réponses (2)

Dave B le 9 Avr 2022
It looks like you're passing in a matrix, but I think you want to pass in a vector. Try transposing t?
t=linspace(0,2,16000)';
sol=sin(2*pi*392*t);
si=sin(2*pi*493.88*t);
la=sin(2*pi*440*t);
soundsc([si; la; sol; la; si; si; si])
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Jan le 9 Avr 2022
You create a [7 x 16000] matrix and ask soundsc to play it. The error message is:
Error using sound (line 76)
Only one- and two-channel audio supported.
(You left out this most important part of the message - please post the complete message in future questions). Solution: Define the time as column vector:
t = linspace(0,2,16000).';
% ^^
sol = sin(2*pi*392*t);
si = sin(2*pi*493.88*t);
la = sin(2*pi*440*t);
soundsc([si; la; sol; la; si; si; si])
2 commentairesAfficher AucuneMasquer Aucune
Giovanni Scamardo le 9 Avr 2022
could you tell me how to write?
Jan le 10 Avr 2022
I do not understand your question. I've posted running code already and marked the difference with "^^". If t is a column vector, sol, si and la are column vectors also. Then [si; la] creates a column vector.
Remember: [a,b] concates horizontally, [a;b] vertically. Try it:
a = rand(2, 2);
b = rand(2, 2);
size([a; b])
ans = 1×2
4 2
size([a, b])
ans = 1×2
2 4

Connectez-vous pour commenter.

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by