how to store data in a matrix?

3 views (last 30 days)
Lilya on 17 Jul 2019
Commented: Lilya on 17 Jul 2019
Hi all,
I want to loop over the third dimension of the 3D matrix and calculate the average then sore the resulted data in a new matrix.
For example:
U10_series = [];
for day=1:length(datenum_array); % this time is corresponding to the number of days
%read U10
U10 = ncread(filename,'U10M');
U10_box = U10(lon_range,lat_range,:);
U10_box_mean = nanmean(U10_box,3);
U10_series = [U10_series,U10_box_mean];
where am I mistaken?
The help is much appreciated

Accepted Answer

KSSV on 17 Jul 2019
U10 = ncread(filename,'U10M');
If your variable U10M is 3D, the above line reads complete data. Your U10 should be 3D. Now you can apply mean on it by specifying the dimension you want.
Also read about ncread, here you can specify the 3D dimension you want to read in a loop. If it is not clear, attach your file for further help.
Lilya on 17 Jul 2019
Thank you very much!

Sign in to comment.

More Answers (0)


Find more on Mathematics and Optimization 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!