error in the code

5 次查看(过去 30 天)
Giovanni Scamardo
评论: Jan 2022-4-10
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])

回答(2 个)

Dave B
Dave B 2022-4-9
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])

Jan
Jan 2022-4-9
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 个评论
Giovanni Scamardo
could you tell me how to write?
Jan
Jan 2022-4-10
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by