Dynamically read all files in a file process them and combine the processed data in one matrix

2 ビュー (過去 30 日間)
Dexter
Dexter 2021 年 11 月 24 日
コメント済み: Dexter 2021 年 11 月 25 日
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
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.
Dexter
Dexter 2021 年 11 月 25 日
That worked, thank you.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by