Matlab 音频播放器数组

发布于 2024-11-07 10:25:26 字数 557 浏览 1 评论 0原文

我正在labview 中创建一个matlab 脚本。在该脚本中,我尝试创建音频播放器对象的数组。但是,我遇到了错误,并且找不到解决方法。

这是脚本:

nrOfSounds = 11;
if (exist('p') == 0)
    [snd, freq, bps] = wavread('sounds/1.wav');
    p = audioplayer(snd, freq);
    for t=2:nrOfSounds
        [snd,freq,bps] = wavread(strcat('sounds/',num2str(t),'.wav'));
        s = audioplayer(snd,freq);
        p(end+1) = s;
    end
end

这就是错误:

Audioplayer objects cannot be concatenated.

似乎我无法创建音频播放器对象的数组,但我无法真正找到解决此问题的方法,因为我对 matlab 没有真正的经验。谁能帮我解决这个问题吗?

I am creating a matlab script inside labview. Inside that script I try to create an array of audioplayer objects. However, I got an error, and I can't find a way around it.

This is the script:

nrOfSounds = 11;
if (exist('p') == 0)
    [snd, freq, bps] = wavread('sounds/1.wav');
    p = audioplayer(snd, freq);
    for t=2:nrOfSounds
        [snd,freq,bps] = wavread(strcat('sounds/',num2str(t),'.wav'));
        s = audioplayer(snd,freq);
        p(end+1) = s;
    end
end

And this is the error:

Audioplayer objects cannot be concatenated.

It seems that I can't create an array of audioplayer objects, but I can't really find a way around this since I'm not really experienced with matlab. Can anyone help me with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘴硬脾气大 2024-11-14 10:25:26

您必须使用单元格,而不是数组。

nrOfSounds = 11;
if (exist('p') == 0)
    [snd, freq, bps] = wavread('sounds/1.wav');
    p{1} = audioplayer(snd, freq);
    for t=2:nrOfSounds
        [snd,freq,bps] = wavread(strcat('sounds/',num2str(t),'.wav'));
        s = audioplayer(snd,freq);
        p{end+1} = s;
    end
end

You have to use cells, not arrays.

nrOfSounds = 11;
if (exist('p') == 0)
    [snd, freq, bps] = wavread('sounds/1.wav');
    p{1} = audioplayer(snd, freq);
    for t=2:nrOfSounds
        [snd,freq,bps] = wavread(strcat('sounds/',num2str(t),'.wav'));
        s = audioplayer(snd,freq);
        p{end+1} = s;
    end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文