I have sensors values in the form of multiple csv's want to read each file and if the length is less than 800 take average of each column and insert in the last of csv

2 ビュー (過去 30 日間)
shery khan
shery khan 2022 年 6 月 25 日
コメント済み: shery khan 2022 年 6 月 26 日
following is the code i am testing on single file where as i have multiple files that have missing values i want to know how can i check the length of file and ignore first column and if length is less then 800 row get the length first and take average of each column and add average at the end of file . suppose a file have 631 rows . so i need to fill left rows by average means 169 values are filled .
1st Row 2nd 3rd 4th
--
631Row
average value
average value
--
--
--
800 Rows
i have files that contain 4 columns but i am working on 3 columns first column is ignored
Kindly help me in this regard ..
tmp=load('D:\Testing\1464882962.m_proc_gyro.csv');
if(length(tmp)~=800)
for i=1:length(tmp)
Imp_three=tmp(:,2:end);
First_col=Imp_three(:,1);
Second_col=Imp_three(:,2);
Third_col=Imp_three(:,3);
M1=mean(First_col);
M2=mean(Second_col);
M3=mean(Third_col);
s1 = size(First_col,1); % Rows
s2 = size(Second_col,2);
s3 = size(Third_col,3);
MArray=[M1,M2,M3];
end
end

採用された回答

Voss
Voss 2022 年 6 月 25 日
編集済み: Voss 2022 年 6 月 25 日
This will do that, including the first column (which you can continue to ignore):
tmp=load('D:\Testing\1464882962.m_proc_gyro.csv');
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
  6 件のコメント

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 6 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by