Hi, I have matrix of data and I would like to decimate the data with command "decimate(x,r)". The matrix has 100 rows. I tried to get it with FOR loop for decimation each row but still wrong. I just get the first decimated row. Here is my code
data %matrix of data
r=10; %decimation factor
% n=100; %number of rows
for i=1:size(data,1)
x=data(i,:);
y=decimate(x,r);
end
Thanks

 Akzeptierte Antwort

Image Analyst
Image Analyst am 13 Jun. 2014

2 Stimmen

How about
outputMatrix = data(1:10:end, :);

4 Kommentare

kubyk
kubyk am 13 Jun. 2014
Thanks for your answer, but I need all 100 rows. Not each 10th. My each row has about 75 000 samples and I would like to decimate it to 7500. Thanks
If you need the number of columns reduced instead of the number of rows, you should do it this way:
outputMatrix = data(:, 1:10:end);
and then read the "Getting Started" documentation on indexing.
kubyk
kubyk am 13 Jun. 2014
of course, I am stupid... thanks a lot
Even so, later I would like to process row by row. Each row give me some information about EEG response. Question is how to do the loop which will go through the matrix row by row.
Matthew
Matthew am 6 Mär. 2015
Bearbeitet: Matthew am 6 Mär. 2015
The decimate function doesn't simply remove data points. It actually low-pass filters the data before downsampling. So decimate(x, r) and x(1:r:end) don't return the same results.
If you actually want to use the decimate function, as far as I can tell you have to use a for loop. I came across this question when I was trying to solve this same problem.
To address the OP's question, in your code, every loop iteration overwrites the value of y. I think the correct way to do it is something like:
y = zeros( size(data,1), ceil(size(data,2)/r) );
for i = 1:size(data,1)
x = data(i, :);
y(i, :) = decimate(x,r); % <<< this was the mistake
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 13 Jun. 2014

Bearbeitet:

am 6 Mär. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by