Error in using NaN value and calculate the mean of each row
조회 수: 1 (최근 30일)
이전 댓글 표시
I have file that has a different number of column in each row. Than i had to calculate the mean value of each row start from column 4 to end of column. I used this script but still facing some errors
clear;
clc;
format short;
f = dir('D:\full_Data_Cryosat_c2p0004.txt');
A=1:length(f);
D = f(A).name;
readlines = @(f)regexp(fileread(f),'\r?\n','split');
data=readlines(D);
for k=1:size(data,1)
qdata=[];
kelompok=data(k,:);
index=arrayfun(@(kelompok),'uniformoutput',false);
qdata=kelompok(index,1);
sigma=std(qdata(:,4:end));
rata2=mean(qdata(:,4:end));
batas_atas=rata2+3*sigma;
batas_bawah=rata2-3*sigma;
id_qc=find(qdata(:,4:end)>=batas_bawah & qdata(:,4:end)<=batas_atas);
qdata_qc=qdata(id_qc,:);
exp_data = [];
for i=1:size(qdata,1)
waktu = sprintf('%d/%d/%d',qdata_qc(i,4),qdata_qc(i,5),qdata_qc(i,6));
exp_data = [exp_data; {num2str(qdata_qc(i,1)) num2str(qdata_qc(i,2)) num2str(qdata_qc(i,3)) waktu num2str(k)}];
end
exp_data = [header; exp_data];
file_name = ['Msl_.txt'];
dlmwrite(file_name, exp_data, 'delimiter', '\t');
end
thankss
댓글 수: 0
답변 (1개)
Image Analyst
2021년 10월 20일
Did you try mean():
rowMeans = mean(data(:, 4:end), 2, 'omitnan');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Transformation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!