# error in the code

3 visualizzazioni (ultimi 30 giorni)
Giovanni Scamardo il 9 Apr 2022
Commentato: Jan il 10 Apr 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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Dave B il 9 Apr 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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Jan il 9 Apr 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 CommentiMostra NessunoNascondi Nessuno
Giovanni Scamardo il 9 Apr 2022
could you tell me how to write?
Jan il 10 Apr 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

Accedi per commentare.

### Categorie

Scopri di più su Audio Processing Algorithm Design in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by