フィルターのクリア

In an assignment A(I) = B, the number of elements in B and I must be the same. while averaging row in Netcdf file

1 回表示 (過去 30 日間)
Hi,
I want to average the value of CO2 for a fixed height in fixed region in Netcdf file. I wrote code for single file. It's running fine and is given,
alti=ncread('SABER_L2C1.nc','altitude');
co2i=ncread('SABER_L2C1.nc','CO2retr');
timei=ncread('SABER_L2C1.nc','time');
lati=ncread('SABER_L2C1.nc','lat');
loni=ncread('SABER_L2C1.nc','lon');
datei=ncread('SABER_L2C1.nc','date');
for i=1:size(lati,1);
for j=1:size(alti,1);
if lati(i) > -80 && lati(i) <0;
if loni(i) >0 && loni(i) <100;
lat(i)=lati(i);
lon(i)=loni(i);
if alti(j)==120;
alt(j)=alti(j);
co2a(j,i) = co2i(j,i);
co2ab=mean(co2a,2);
date1=mean(datei,1);
end
end
end
end
end
When trying to do it for large number of files (~400) using cell, I am getting error "In an assignment A(I) = B, the number of elements in B and I must be the same". My code using cell is below, nc = cell(1, numfiles);
for k = 1:numfiles
nc= netcdf.open(files(k).name);
alti{k}=ncread(files(k).name,'altitude');
co2i{k}=ncread(files(k).name,'CO2retr');
timei{k}=ncread(files(k).name,'time');
lati{k}=ncread(files(k).name,'lat');
loni{k}=ncread(files(k).name,'lon');
datei{k}=ncread(files(k).name,'date');
end
for k=1:numfiles;
for i=1:size(lati{k},1);
for j=1:size(alti{k},1);
if lati{k}(i) > -80 && lati{k}(i) <0;
if loni{k}(i) >0 && loni{k}(i) <100;
lat{k}(i)=lati{k}(i);
lon{k}(i)=loni{k}(i);
if alti{k}(j)==120;
alt{k}(j)=alti{k}(j);
co2a{k}(j,i) = co2i{k}(j,i);
co2ab(k)=mean(co2a{k},2);
date1(k)=mean(datei{k},1);
end
end
Need help. Thank you so much.

採用された回答

Walter Roberson
Walter Roberson 2017 年 5 月 24 日
You have
co2ab(k)=mean(co2a{k},2);
date1(k)=mean(datei{k},1);
if co2a{k} or datei{k} are empty then you would have a problem. If they are vectors then you would be okay provided that co2a{k} is a row vector and datei{k} is a column vector. But if they are 2D arrays, then mean() is going to return a vector of values, and that vector is not going to fit into co2ab(k) or date1(k)
  5 件のコメント
Walter Roberson
Walter Roberson 2017 年 5 月 24 日
Mean of that row, or mean of that column?
mean(co2a{k}(j,:)) %perhaps
Madan Kumar
Madan Kumar 2017 年 5 月 24 日
It should be mean of row. It worked. Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by