Decimate every row in a matrix

4 views (last 30 days)
Edward Keavney
Edward Keavney on 14 Sep 2022
Answered: Chunru on 14 Sep 2022
Hi,
I have an array 26X10600 and have successfully managed to decimate the data to the required factor, however the decimate function only applies this to the first row in the array.
Is there a way to apply the decimate function to all the rows in the array? Perhaps using a loop?
Thanks in advance,
Ed.

Answers (1)

Chunru
Chunru on 14 Sep 2022
% assume that decimate is used for downsampling
a = randn(100, 26); % time is along the column
[ns, nch] = size(a);
r = 5;
ns_down = floor(ns/r);
a_down = zeros(ns_down, nch);
for i=1:nch
a_down(:, i) = decimate(a(:, i), r);
end
% if you use resample
a_down = resample(a, 1, 5)
a_down = 20×26
0.2035 0.5894 0.4277 0.5124 -0.2946 0.0375 -0.4256 0.5500 -0.0988 -0.3491 -0.2059 -0.1932 -0.0076 0.1527 -0.1606 -0.4525 -0.2297 -0.3152 0.3082 -0.1657 0.0273 0.6115 -0.1139 -0.2836 -0.0841 -0.4076 0.0088 0.7556 -0.3695 0.3144 0.2809 0.0622 0.2201 0.4081 -0.4480 0.1609 0.3844 0.0006 0.2010 0.6847 -0.6279 -0.6199 -0.5940 -0.5327 -0.1417 -0.5802 0.0935 0.1891 0.3220 0.2975 0.1581 -0.7951 0.7662 0.1463 0.0618 -0.1744 -0.5694 -0.6003 -0.2815 0.2072 0.0655 -0.0817 0.4674 -0.2274 0.5296 -0.3111 -0.2398 -0.5233 0.1860 0.3026 -0.3302 -0.1080 -0.0559 0.4351 -0.0301 0.5064 0.7205 0.5174 -0.0342 0.8585 0.1987 0.0411 -0.0507 0.0990 -0.1219 -0.0178 0.3059 0.3170 -0.1951 -0.7662 -0.2090 0.0570 0.2217 -0.8785 0.2394 0.2453 0.6089 -0.5470 -0.0330 0.4841 0.2075 -0.0729 -0.1621 -0.3895 -0.8904 -0.3186 -0.0481 -0.3479 -0.1071 -0.0601 0.3548 -0.4403 0.2610 0.1760 0.7389 0.3950 -0.0848 -0.4017 0.4266 -0.3536 -0.3203 -0.6671 -0.0697 -0.5183 -0.3654 -0.0970 0.4209 0.6660 0.3831 0.0612 -0.3664 0.0807 -0.4412 0.3605 0.7926 0.4394 0.6065 -0.7204 0.2546 -0.3633 -0.5788 -0.5178 -0.5565 -0.1363 0.6631 -0.3883 -0.0159 -0.8875 -0.2291 -0.1563 -0.7098 0.5201 -0.0395 0.8904 0.4703 0.3960 0.2005 0.0582 -0.6620 0.5480 0.5580 0.2919 0.5541 0.3168 -0.9495 -0.8333 -0.7845 -0.1338 0.4028 0.5476 0.1172 -0.9842 0.1029 0.0986 -0.1060 -0.3599 0.6724 -0.1903 0.7076 0.2337 -0.0446 -0.1107 -0.2820 0.1991 -0.1359 -0.2455 -0.9743 -0.0588 0.2309 0.8561 0.0654 -0.5078 0.3556 0.1620 0.4531 0.3374 0.2375 -0.5716 0.5632 -0.4275 -0.1056 -0.1951 0.2659 -1.0951 0.4419 -0.4905 0.3387 0.1454 0.7738 0.5488 -0.1856 0.9091 -0.2801 -0.5387 -0.1921 -0.1776 0.1818 0.0328 0.4397 0.5422 -0.3121 -0.1097 -0.4251 -1.4804 -0.0117 0.2012 0.3562 -0.7029 0.4486 0.3344 -0.4861 0.0063 -0.7187 -0.3091 0.7240 0.6699 0.3239 -0.1987 -0.6077 -0.2540 0.2003 0.8084 0.7762 -0.2350 0.0293 0.4720 0.3072 0.1202 0.1659 -0.1834 -0.0185 -0.2352 -0.7081 -0.2282 -0.3236 0.4145 -0.1915 0.1940 0.2924 -0.2986

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!