How to average finite components only of 4 data?
1 次查看(过去 30 天)
显示 更早的评论
My question is that I have four 3D ocean data(360*160*50). I want to average the finite numbers of the 4 data. For example:
data1(1,2,3) = NaN;
data2(1,2,3) = 3;
data3(1,2,3) = NaN;
data4(1,2,3) =4
In this case, I will sum data2(1,2,3) and data4(1,2,3) and then dividid by 2. How to do it for the whole data?
It needs to be taken into account that continent area of the 4 data are all NaN because it is ocean data. Due to this, I can not replace all the NaN to be zero.
0 个评论
采纳的回答
Stephan
2019-3-20
Hi,
% create example data containing NaN values
data1 = randi(100,5,4,3);
data2 = randi(100,5,4,3);
data3 = randi(100,5,4,3);
data1(randperm(60,15))= NaN;
data2(randperm(60,15))= NaN;
data3(randperm(60,15))= NaN;
% calculate the average ignoring NaN-data
result = mean(reshape(vertcat(data1,data2,data3),[],1),'omitnan')
Since the first 6 rows are just for the example you can do it in one line of code.
Best regards
Stephan
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Oceanography and Hydrology 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!