replacing every 30 data points with the mean of them, in an 8 column matrix x 65000 data points. Reshape error

1 view (last 30 days)
This code has been running well for me and now all of a sudden i keep getting reshape error. i have changed nothing, but for some reason the data is being reshaped into a number not divisible by 30. I should be ending up with an 8 x 2166 matrix
%find the mean of every nth elements
n=30; % no. of samples to average at a time
filt_data=rmmissing(plot_thresh_data);
data_size=length(filt_data)-rem(length(filt_data),n);%make sure data is divisible by block size
y = filt_data(1:data_size,:); %resize data to divisible size
x =reshape(mean(reshape(y,n,[])),[],30);% replace each 30 data points with the mean of that 30

Answers (1)

Matt J
Matt J on 22 Jan 2022
Edited: Matt J on 22 Jan 2022
I should be ending up with an 8 x 2166 matrix
I assume you mean 2166 x 8.
plot_thresh_data=rand(65000,8);
[M,N]=size(plot_thresh_data);
n=30; % no. of samples to average at a time
filt_data=rmmissing(plot_thresh_data);
data_size=M-rem(M,n);%make sure data is divisible by block size
y = filt_data(1:data_size,:); %resize data to divisible size
x =reshape(mean(reshape(y,n,[])),[],N);% replace each 30 data points with the mean of that 30
whos x
Name Size Bytes Class Attributes x 2166x8 138624 double

Categories

Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!