Dynamically read all files in a file process them and combine the processed data in one matrix
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 25 de Nov. de 2021
"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.
Respuestas (0)
Ver también
Categorías
Más información sobre Multirate Signal Processing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!