Dynamically read all files in a file process them and combine the processed data in one matrix
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have a folder with various datasets, I want to read all the datasets and process them. Each datasets have 4 columns (A, B, C , D),
each column represent a signal that I want to process, in this case to filter and calculate the rms value of the signal. The final result should be a table with columns A,B,C,D and row(i) should have the rms values of the signas(i), i.e the rms values of the first dataset . My main problem is that when using reshape, in the second iteration, I am getting:
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
files = dir('*.csv');
num_files = length(files);
results = cell(length(files), 1);
for i = 1:num_files
results{i} = readmatrix(files(i).name);
end
%
% results{2}
features = []
results_k = results{1}
for i = 1:num_files
results_k = results{i}
len = length(results_k)
results_k = results_k(~isnan(results_k))';
%len = len/4
results_k = reshape(results_k,len,4)
firstCol = results_k(:,1)
secondCol = results_k(:,2)
thirdCol = results_k(:,3)
fourthCol = results_k(:,4)
bpFilt = designfilt('bandpassiir','FilterOrder',4, ...
'HalfPowerFrequency1',0.08,'HalfPowerFrequency2',1, ...
'SampleRate',20,'DesignMethod','butter');
firstCol = filtfilt(bpFilt,firstCol);
secondCol = filtfilt(bpFilt,secondCol);
thirdCol = filtfilt(bpFilt,thirdCol);
fourthCol = filtfilt(bpFilt,fourthCol);
rms1 = rms(firstCol)
rms2 = rms(secondCol)
rms3 = rms(thirdCol)
rms4 = rms(fourthCol)
new_features=[rms1,rms2,rms3,rms4]
features = [features new_features]
end
5 个评论
Stephen23
2021-11-25
"I tried reshape but doesnot work like I want to. "
I am guessing that you need to RESHAPE to have four rows, and then TRANSPOSE.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!