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!