error in the code

6 ビュー (過去 30 日間)
Giovanni Scamardo
Giovanni Scamardo 2022 年 4 月 9 日
コメント済み: 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
Giovanni Scamardo 2022 年 4 月 9 日
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 Center および File ExchangeAudio 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