mean regression of variable in multiple nc files

조회 수: 6 (최근 30일)
aine gormley
aine gormley 2019년 2월 12일
댓글: aine gormley 2019년 2월 13일
Please can someone advise on my code for Matlab. I am trying to do linear regression on the TXx variable across 5 netcdf files. I have multiple approaches to this but still getting error.
With the current code, the exact error is: "Error using regress Y must be a vector and must have the same number of rows as X."
(this is because the output latitude dimension of mean_TXx5s is 1 x 288 x 30 and it should be 192 x 288 x 30), so I can see why the error but I cannot seem to solve the problem.
NB: the dimensions of TXx (maximum temperature at each lat/lon at each timestep) are 288 x 192 x 30. Time is 30 years, timestep=1year.
% initialise time parameters
time_begin = [1981, 1, 1, 0,0,0];
time_end = [2010,12,31,23,0,0];
years = (time_begin(1):time_end(1))';
nyears = length(years);
% create storage and regress
TXx5s = [];
num_files = 5;
for i = 1 : num_files
TXx5 = randi(100, 288, 192, 30);
lat = rand(192, 1);
lon = rand(288, 1);
time = rand(30,1);
TXx5s = cat(4, TXx5s, TXx5);
end
M = numel(lon);
N = numel(lat);
T = numel(time);
x = ([ones(T, 1) years]);
mean_TXx5s = mean(TXx5s);
mean_TXx5s=permute(mean_TXx5s,[2,1,3,4]);
slope_TXx5 = zeros(M, N);
intercept_TXx5 = zeros(M, N);
for i = 1 : M
for j = 1 : N
y_TXx5 = squeeze(mean_TXx5s(i, j, :));
c = regress(y_TXx5, x);
intercept_TXx5(i, j) = c(1);
slope_TXx5(i, j) = c(2);
end
end

답변 (1개)

Satoshi Kobayashi
Satoshi Kobayashi 2019년 2월 13일
mean_TXx5s = mean(TXx5s);
Function mean calculates the mean along lon.
mean_TXx5s = mean(TXx5s,4);
  댓글 수: 1
aine gormley
aine gormley 2019년 2월 13일
thank you very much for your time, i will give it a try

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by