Error in calculate mean and standar deviation
조회 수: 1 (최근 30일)
이전 댓글 표시
Helloo, i had a problem with the script. So i used this script to calculate mean and standar deviation of each row from column 4 to end. I used this script and work in first file but in the next file i face some error like this
Warning: Variable names were modified to make them valid MATLAB identifiers.
The original names are saved in the VariableDescriptions property.
Error using script_msl_v2 (line 17)
Variable index exceeds table dimensions.
With this script and the file
clear;
clc;
format longG;
f = dir('E:\Sentinel-Cryosat\sentinel\full_Data_Sentinel_c2p0006.txt');
A=1:length(f);
D = f(A).name;
ff= D(:,20:26)
data=readtable(D,'HeaderLines',0);
rata2=mean(data{:,4:end},2,'omitnan');
standar_deviation=std(data{:,4:end},[],2,'omitnan');
%ud=getTrend(data{:,4:end},2,'omitnan');
%ref=data{:,1};
lat=data{:,2};
lon=data{:,3};
msl=[lat lon rata2 standar_deviation]
%file_name_msl=['msl_' ff '.txt']
%dlmwrite(file_name_msl, rata2, 'delimiter', '\t');
file_name_data=['data_rata2_std_' ff '.txt']
dlmwrite(file_name_data, msl, 'delimiter', '\t','precision',10);
Thanks to anyone who can help me
댓글 수: 0
답변 (1개)
Matt J
2021년 11월 16일
Why not just
data=readtable('E:\Sentinel-Cryosat\sentinel\full_Data_Sentinel_c2p0006.txt','HeaderLines',0);
댓글 수: 3
Matt J
2021년 11월 16일
Remove the previous lines of code,
data=readtable('E:\Sentinel-Cryosat\sentinel\full_Data_Sentinel_c2p0006.txt','HeaderLines',0);
rata2=mean(data{:,4:end},2,'omitnan');
standar_deviation=std(data{:,4:end},[],2,'omitnan');
%ud=getTrend(data{:,4:end},2,'omitnan');
%ref=data{:,1};
lat=data{:,2};
lon=data{:,3};
msl=[lat lon rata2 standar_deviation]
%file_name_msl=['msl_' ff '.txt']
%dlmwrite(file_name_msl, rata2, 'delimiter', '\t');
file_name_data=['data_rata2_std_' ff '.txt']
dlmwrite(file_name_data, msl, 'delimiter', '\t','precision',10);
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!