In an assignment A(I) = B, the number of elements in B and I must be the same. while averaging row in Netcdf file
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on NetCDF in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!