How to find the csv that lesser length of rows then 800 and append the same file chunk to fill the missing values.

2 次查看(过去 30 天)
Question No 1 is how can i find those files that have less number of rows or rows are not equal to 800? Question No 2 is after finding those file I want to fill those rows in chunks like if file contain 632 Rows. 32 rows are discarded and append 200 consecutive chunk (this chunk is copied from same file like 1 t0 200 ) at the end of file which make it 800. meaning we are replacing last 32 rows with first 200 rows of this file to complete 800 length of file
Before this i have completed these missing rows with mean code is attached
home_dir = 'D:\DS\Activity_Recognition';
sensors = dir(home_dir);
for sens =3:length(sensors)
classes = dir(fullfile(home_dir, sensors(sens).name));
for cls=3:length(classes)
data = dir(fullfile(home_dir, sensors(sens).name, classes(cls).name));
toWrite = cell(zeros(1,1));
for dat = 3:length(data)
tmp = load(fullfile(home_dir, sensors(sens).name, classes(cls).name, data(dat).name));
tmp = tmp(:,2:end);
% % %
n_rows_target = 800; % extend to 800 rows, with mean of each column
n_rows = size(tmp,1);
if n_rows < n_rows_target
mean_tmp = mean(tmp,1);
tmp(n_rows+1:n_rows_target,:) = repmat(mean_tmp,n_rows_target-n_rows,1);
end
%for 5 Sec
for ch=1:4
xTmp = tmp(((ch-1)*200)+1:ch*200, 1);
yTmp = tmp(((ch-1)*200)+1:ch*200, 1);
zTmp = tmp(((ch-1)*200)+1:ch*200, 1);
xFeat = computeStatFeats(xTmp, length(xTmp));
yFeat = computeStatFeats(yTmp, length(yTmp));
zFeat = computeStatFeats(zTmp, length(zTmp));
toWrite{dat-2, 1} = [xFeat yFeat zFeat];
end
fprintf('Computing %s Features: %d\n', classes(cls).name, length(data)-dat-2);
end
toWrite = cell2mat(toWrite);
writematrix(toWrite, strcat(sensors(sens).name, '_', strrep(classes(cls).name, ' ', '_'), '.csv'));
end
end
  1 个评论
shery khan
shery khan 2022-7-1
Find the file which length is less the 800 then do like
1 to 641
delete last 41 rows
now data in file will be
1 to 600
copy 1 to 200 rows and append in the last
Thanks

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by