필터 지우기
필터 지우기

size reduction and addition operator

조회 수: 1 (최근 30일)
Hernaldo Leyton
Hernaldo Leyton 2016년 5월 17일
댓글: the cyclist 2016년 5월 18일
I have a file with 5 dimensions netcdf, longitude, latitude, levels, days and hours of pollutant emissions (224x178x7x7x24). I need to add (sum) all emissions of every hour of every day and all levels and also reduce the dimension of five to two dimensions. As a result I should be a matrix of latitude and longitude data combined emissions of the last three dimensions of netcdf file. Do I can indicate what form please? First of all, Thanks

채택된 답변

the cyclist
the cyclist 2016년 5월 18일
I'm not sure I understand, but does this code do what you want?
% Some pretend data
netcdf = rand(224,178,7,7,24);
% Sum over each dimension in turn
sum5 = sum(netcdf,5);
sum4 = sum(sum5,4);
sum3 = sum(sum4,3); % This contains the sum for each lat/long.

추가 답변 (1개)

the cyclist
the cyclist 2016년 5월 18일
If the other answer I submitted is what you intended, you can get the same thing with the following one-liner:
% Some pretend data
netcdf = rand(224,178,7,7,24);
sum3 = sum(reshape(netcdf,224,178,[]),3);
  댓글 수: 2
Hernaldo Leyton
Hernaldo Leyton 2016년 5월 18일
Thanks very much.
It was just what I needed
Regards
the cyclist
the cyclist 2016년 5월 18일
The best form of thanks is upvoting and/or accepting answers that are helpful. This rewards the contributor, and can point other users to helpful answers.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by