# error in the code

3 views (last 30 days)
Giovanni Scamardo on 9 Apr 2022
Commented: Jan on 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])

Dave B on 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])

Jan on 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])
Giovanni Scamardo on 9 Apr 2022
could you tell me how to write?
Jan on 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
{"ft_lang_label":"__label__en","ft_lang_prob":0.70361394,"math_prob":0.93217474,"size":1688,"snap":"2023-40-2023-50","text_gpt3_token_len":537,"char_repetition_ratio":0.13123515,"word_repetition_ratio":0.074074075,"special_character_ratio":0.34952608,"punctuation_ratio":0.19277108,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9882732,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-07T13:27:21Z\",\"WARC-Record-ID\":\"<urn:uuid:ca158fa9-bcc5-49f9-9e9e-f86d662bd1e1>\",\"Content-Length\":\"132112\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9ba08412-4424-4c13-b2fd-ae15ac606cc8>\",\"WARC-Concurrent-To\":\"<urn:uuid:1faccbaa-8c04-4765-a4db-1f3d85428551>\",\"WARC-IP-Address\":\"104.108.96.151\",\"WARC-Target-URI\":\"https://www.mathworks.com/matlabcentral/answers/1692610-error-in-the-code\",\"WARC-Payload-Digest\":\"sha1:H6DUAPZ2ODC3W25YHL53TC7S6GQQMB7L\",\"WARC-Block-Digest\":\"sha1:LXXWMXQDXIPJ3GDFVMUSKMGFQ3YPX4N6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100674.56_warc_CC-MAIN-20231207121942-20231207151942-00620.warc.gz\"}"}