Error in using NaN value and calculate the mean of each row

조회 수: 1 (최근 30일)
Retno Purwaningsih
Retno Purwaningsih 2021년 10월 20일
답변: Image Analyst 2021년 10월 20일
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);
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
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

답변 (1개)

Image Analyst
Image Analyst 2021년 10월 20일
Did you try mean():
rowMeans = mean(data(:, 4:end), 2, 'omitnan');

카테고리

Help CenterFile Exchange에서 Data Transformation에 대해 자세히 알아보기

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by