Decimated table exporting same size as original

I am trying to decimate a data file that was recorded at 100Hz and the original size of the file is ~6.16GB. I decimated the data by a factor of 2 (to reduce the sample rate to 50Hz), which seems successful:
However, when exported, the size isn't even 1GB less than the original file:
Is my decimation working correctly? Code below.
%%%% Loop to decimate 3 columns (out of 17 total columns)
s = size(data_XYZ);
r = 2;
n = ceil(s(1)/r);
data_XYZ_50 = zeros(n,s(2));
for k = 1:s(2)
data_XYZ_50(:,k) = decimate(data_XYZ(:,k),r);
end
%%%% Extracing every other line from the columns.
data_50 = data(1:2:end,:);
%%%% Replacing the 3 original columns with the decimated data
data_50{:,3} = data_XYZ_50(:,1);
data_50{:,4} = data_XYZ_50(:,2);
data_50{:,5} = data_XYZ_50(:,3);
save_directory = 'G:\path';
table_path = fullfile(save_directory, 'table.csv');
writetable(data_50,table_path)

8 comentarios

Taylor, I thnk here's what's happening:
t = table([1;2;3],[1;2;3])
t = 3×2 table
Var1 Var2 ____ ____ 1 1 2 2 3 3
t{4:6,2} = [4;5;6]
Warning: The assignment added rows to the table, but did not assign values to all of the table's existing variables. Those variables are extended with rows containing default values.
t = 6×2 table
Var1 Var2 ____ ____ 1 1 2 2 3 3 0 4 0 5 0 6
But
t = table([1;2;3],[1;2;3])
t = 3×2 table
Var1 Var2 ____ ____ 1 1 2 2 3 3
t{4:6,:} = [4 4;5 5;6 6]
t = 6×2 table
Var1 Var2 ____ ____ 1 1 2 2 3 3 4 4 5 5 6 6
Hi Peter,
Thank you, but I'm having trouble implementing that into my code.
%%%% Loop to decimate 3 columns (out of 17 total columns)
s = size(data_XYZ);
r = 2;
n = ceil(s(1)/r);
data_XYZ_50 = zeros(n,s(2));
for k = 1:s(2)
data_XYZ_50(:,k) = decimate(data_XYZ(:,k),r);
end
data_50 = data([3;4;5], [3;4;5]) % This creates a table that is 3x3 and the data I need has millions of rows
data_50{3:5,:} = [3 3;4 4;5 5] % When I try to run this line, I get the below error:
Error using {}
The value on the right-hand side of the assignment has the wrong width. The assignment requires a value whose width is 3.
"data_50 = data([3;4;5], [3;4;5]) % This creates a table that is 3x3"
It doesn't. That's your problem.
I'm sorry - I'm still struggling to figure out what I'm doing wrong here.
This is my code below and I'm having the same problem:
%% Decimate
data50_X = decimate(data{:,["X"]},2)
data50_Y = decimate(data{:,["Y"]},2)
data50_Z = decimate(data{:,["Z"]},2)
% Now I want to combine my decimated data to other untouched raw data.
% To do this, I want to extract every 2nd row (100Hz -> 50Hz).
data_50 = data(1:2:end,:);
% Replace the old acceleration column with the downsampled data
data_50{:,"X"} = data50_X(:,1);
data_50{:,"Y"} = data50_Y(:,1);
data_50{:,"Z"} = data50_Z(:,1);
I'm just confused how data can be 83745100x17 table and data_50 can be 1/2 that (41872550x17 table) and not export at 1/2 of the size of the original file?
Stephen23
Stephen23 el 21 de Ag. de 2023
Editada: Stephen23 el 21 de Ag. de 2023
"However, when exported, the size isn't even 1GB less than the original file"
You are comparing apples with oranges:
  • your original file is an Excel proprietary file of some kind, which either stores compressed text data (e.g. XLSX ultimately uses ZIP) or uses binary to store numeric data (e.g. XLS)
  • your new file is an uncompressed text file.
Different file types containing completely different data, so any comparison between them is basically pointless.
"Is my decimation working correctly?"
Probably, but comparing diffrerent data stored in compressed and uncompressed data files is not going to tell you if your decimation if working or not (hint: check the variable size in MATLAB).
"I'm just confused how data can be 83745100x17 table and data_50 can be 1/2 that (41872550x17 table) and not export at 1/2 of the size of the original file?"
Here is the explanation:
Taylor Azizeh
Taylor Azizeh el 21 de Ag. de 2023
Editada: Taylor Azizeh el 21 de Ag. de 2023
Oh that is super helpful! Thank you for explaining that so concisely. However, when I exported it as a CSV (this is the format I need), it is the same size.
Are you saying that if my variable size in MATLAB looks decimated: 83745100/2 = 41872550, then it should be working?
Stephen23
Stephen23 el 21 de Ag. de 2023
"However, when I exported it as a CSV (this is the format I need), it is the same size."
A CSV file is just an uncompressed text file, why should it be any different?
"Are you saying that if my variable size in MATLAB looks decimated: 83745100/2 = 41872550, then it should be working?"
You could check it yourself: take the first few values, calculate by hand what you expect the "decimated" values to be.
I would just assume that if you have half of the rows of data, logically, your file should be half the size.

Iniciar sesión para comentar.

Respuestas (0)

Productos

Versión

R2023a

Preguntada:

el 17 de Jul. de 2023

Comentada:

el 21 de Ag. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by