Decimation function needs a double precision vector

I am trying to decimate some data that was recorded at 100Hz down to 50Hz. So far, I extracted the three columns to decimate and tried:
data_X = data(:,[3])
Unrecognized function or variable 'data'.
It's a massive file, so here is the ouput preview, so you can get an idea of what is going into the next piece of code.
Then, I am trying to run the decimate function using...
data_X_50 = decimate(data_X,2);
resulting in this error:
.
I am very new to coding in MatLab and this is my first time posting a question here, so I really appreciate any help.

 採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 7 月 13 日
編集済み: Dyuman Joshi 2023 年 7 月 13 日

0 投票

Using parentheses () on table returns a sub-table.
x = primes(20)';
y = (1:numel(x))';
T = table(x,y)
T = 8×2 table
x y __ _ 2 1 3 2 5 3 7 4 11 5 13 6 17 7 19 8
%When you use (), Output is returned as a table
T(:,1)
ans = 8×1 table
x __ 2 3 5 7 11 13 17 19
Use curly braces
T{:,1}
ans = 8×1
2 3 5 7 11 13 17 19
or dot indexing to access the content of the table in the stored format -
T.(1)
ans = 8×1
2 3 5 7 11 13 17 19
This assumes that the initial data is of double format. If it is of single format (which seems to be the only other option with the data given), convert it to double.

6 件のコメント

Taylor Azizeh
Taylor Azizeh 2023 年 7 月 13 日
Amazing - that worked perfectly for one column (X). But doesn't seem to work if I try to include more than one colum:
data_XYZ = data{:,[3 4 5]}
I try to decimate and get the same error:
data_XYZ = 124826901×3
-0.1250 -0.0630 1.0000
-0.1250 -0.0630 0.9390
-0.1230 -0.0630 1.0000
-0.0660 -0.0630 0.9970
-0.1250 -0.0630 0.9430
-0.1190 -0.0630 1.0000
-0.0700 -0.0630 0.9930
-0.1160 -0.0630 0.9470
-0.0630 -0.0630 1.0000
-0.0630 -0.0630 1.0000
data_XYZ_50Hz = decimate(data_XYZ,2);
Error using decimate>validateinput
The input signal X must be a double-precision vector.
Error in decimate (line 46)
validateinput(idata,r);
Do you think I'll have to go one column at a time?
Dyuman Joshi
Dyuman Joshi 2023 年 7 月 13 日
"Do you think I'll have to go one column at a time?"
Yes, because the expected input to the function is a vector (as the error states as well). Whereas data_XYZ_50Hz is not a vector.
You will have to use a for loop going through each column.
Taylor Azizeh
Taylor Azizeh 2023 年 7 月 13 日
Okay, thank you... Now on to trying to write my first for loop.
Taylor Azizeh
Taylor Azizeh 2023 年 7 月 13 日
Could you advise me on how to get started, Dyuman?
Dyuman Joshi
Dyuman Joshi 2023 年 7 月 13 日
data_XYZ = data{:,[3 4 5]};
%Get the size of the array
s = size(data_XYZ);
%Decimation factor
r = 2;
%The decimated signal is shortened by a factor of r, so the length of
%output will be
n = ceil(s(1)/r);
Reference for the length - decimate
%Preallocating the final output
out = zeros(n,s(2));
%looping through the columns of the data
for k=1:s(2)
out(:,k) = decimate(data_XYZ(:,k),r);
end
Taylor Azizeh
Taylor Azizeh 2023 年 7 月 13 日
Thank you so much for your help, Dyuman!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by