# Stuck in endless loop

2 ビュー (過去 30 日間)
desert_scientist90 2019 年 10 月 24 日

Hi all,
I am learning matlab thru practice and patience. I am trying to create a loop to get the mean of a precipitation dataset with a 0.5 grid spacing and dimensions x=141, y=71 and t =38. I am trying to build a structure to get the means per grid over each layer (38). I am running the following code but matlab is stuck in a endless loop. Is there any way to fix this to avoid getting stuck? Thanks in advance for your help
for t=1:38
for x=1:141
for y=1:71
meanprecip(y,x,t)=nanmean(rain(y,x,t))
end
end
end
##### 6 件のコメント表示非表示 5 件の古いコメント
desert_scientist90 2019 年 10 月 24 日
t=38 represents the years.

サインインしてコメントする。

### 回答 (1 件)

Siriniharika Katukam 2019 年 10 月 29 日

Hi,
As per my understanding, you are trying to find the mean of grid at each layer. In your case, if the output of rain(y,x,t) is a scalar, then calculating mean of a scalar is like reassigning. It is similar to
meanprecip(y,x,t) = rain(y,x,t);
If you want to calculate the mean of the grid at each year,
Try this:
for t=1:38
meanprecip(t) = mean(rain(:,:,t))
end
Moreover, your code is not an endless loop.

サインインしてコメントする。

### カテゴリ

Find more on Interactive Control and Callbacks 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!