How do we resample data from tables and doubles? The resulting table/double produced by the resample function, replaces the data (floats) in each of the cells with zeros (0).

5 views (last 30 days)
I used the resample function on my table. I had to first use the function table2array because matlab couldn't proceed with the resample function with the type of my variable set as table, that function only executes on doubles.
Unfortunately, the cells produced are all filled with zeros (0). My original data is gone and replaced in the process when I use the resample function.
N = table2array(newTable);
M = [];
for i = width(N)
M(:,i) = resample(N(:,i),120,40)
end
  1 Comment
dpb
dpb on 27 Jul 2022
Edited: dpb on 28 Jul 2022
"... had to first use the function table2array..."
Au contraire -- you dereference the table to return the desired variable; you don't want to operate on the table itself but the data within that table. No different than dereferencing a struct field with dot notation or a cell array with "the curlies". Both are available with the table data structure; there's a link at the bottom of the page to complete documentation on referencing table variables in all the myriad possible ways.
We can't begin to diagnose a problem with resample itself without the data to look at, though...

Sign in to comment.

Answers (1)

Nipun
Nipun on 27 Sep 2023
Hi Komi,
I understand that you are trying to resample data from a table using the resample function. However, the type float values in the table are reassigned to 0 after the subroutine.
Here I should remark that the resample function in MATLAB requires an input data sequence. You need not convert your table to an array everytime you resample. You may use braces indexing to extract the table data as an array and resample. I am attaching an example code that takes a table as an input and resamples each column 20 times, creating a new table.
x1 = linspace(0.1,0.9,20);
x2 = linspace(1.3,3.9,20);
T = table(x1',x2');
newT = [];
for c=1:size(T,2)
newT = [newT resample(T{:,c},10,1)];
end
newT = array2table(newT)
Hope this helps.
Regards,
Nipun

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!