Reputation: 6554
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?
Upvotes: 2
Views: 282
Reputation: 12737
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
Upvotes: 3