I have a wav signal that I read in samples in a buffer s. I want to save in a new buffer x the samples that are in 10 position, 20, 30..110 position. How can I do this? I must write a for loop but how can I write the contator?
Asked
Active
Viewed 51 times
2 Answers
1
Not sure what you mean by buffer, but here's how you'd get that info out of an array. Given s = 1:107
, you could get the elements starting at position 10
by issuing the command:
b = s(10:10:end);
Now, b
equals 10 20 30 40 50 60 70 80 90 100

houtanb
- 3,852
- 20
- 21
0
I want to save in a new buffer x the samples that are in 10 position, 20, 30..110 position. How can I do this?
x = s(10:10:110);
This would work too:
x = s(10*(1:11));
Houstanb's solution is best if you want every 10th sample from your buffer s, and not just up to 110 as you state.
I must write a for loop but how can I write the contator?
If you must write a for loop then you can try this:
x = nan(1,11);
for k=1:11
x(k) = s(k*10);
end
But this is not a great solution from a MATLAB perspective, where vectorization is preferred.

informaton
- 1,462
- 2
- 11
- 20