Error in using NaN value and calculate the mean of each row
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Image Analyst
le 20 Oct 2021
Did you try mean():
rowMeans = mean(data(:, 4:end), 2, 'omitnan');
0 commentaires
Voir également
Catégories
En savoir plus sur Data Transformation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!