Adding years to matrix

2 Ansichten (letzte 30 Tage)
desert_scientist90
desert_scientist90 am 24 Okt. 2019
Kommentiert: Peter Perkins am 30 Okt. 2019
Hi all,
I am newbie on matlab, I have a dataset for precipitation with a grid of 0.5 spacing x=141, y=71 and t=38. I calculated the average using the following code, But I will like to add the years 1:38 to be able to identify the values with their respective dates. Can I add the dates at this step or should I do it to the original dataset attached?
Thanks in advance for your help.
meanprecip = nanmean(rain(141,71,38));
for x=1:141
for y=1:71
meanprecip(x,y)=mean(rain(x,y))
end
end
  1 Kommentar
Peter Perkins
Peter Perkins am 30 Okt. 2019
d_s90, I'm not sure I understand your question. It appears as if you have rainfall data collected over 38 years(?) on a 141x71 spatial(?) grid. But then it looks like you are trying to compute the means for each location over the entire time span.
So time would go away at that point. Can you clarify what you want to do?
If you want to find means at each location, you don't need any loops, mean(rain,3) would compute means across your time dimension.
Also, meanprecip = nanmean(rain(141,71,38)) almost certainly doesn't do what you want, which I think is to pre-allocate. meanprecip = nan(size(rain)) maybe?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by