Index exceeds matrix dimensions

1 回表示 (過去 30 日間)
Alexandra Ridgway
Alexandra Ridgway 2017 年 2 月 11 日
コメント済み: Walter Roberson 2017 年 2 月 13 日
Hi, my tutor is sick of my questions, please help!
for j=2:31
dz(j)=abs(depth(j)-depth(j-1))
end
for i=1:360
for j = 1:180
for k=1:31
intFe68 = Fe68(i,j,k) *dy(360) * dx(j) * dz(j)
end
end
end
nansum(intFe68)
Fe68 has dimensions 360x180x31. It is iron data from a model. I can contour a hydrothermal plume by plotting Fe68 against depth and longitude, below I am trying to get one value for the size of the plume in m^3 but matlab doesn't like the second loop due to the 'index exceeding the matrix dimensions'. Im also not sure if I need the first loop, or what to put in the second loop if I do, dz(j), dz(:), dz(k)..
Any help would be very appreciated!
Alex
  2 件のコメント
Chad Greene
Chad Greene 2017 年 2 月 11 日
Hi Alex,
What exactly do you mean by "integrate up to get one value"? Perhaps describing the context and what you're trying to do will help. This looks like maybe a month's worth of ocean iron content data? What exactly are you trying to calculate?
Alexandra Ridgway
Alexandra Ridgway 2017 年 2 月 11 日
編集済み: Alexandra Ridgway 2017 年 2 月 11 日
Hi Chad, it's iron data from a model. I can plot a hydrothermal plume by plotting Fe68 against longitude however I want to quantify the size of the plume. (Im not sure if that would involve integrating...) Does that help at all? Thank you for trying to help me!

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

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 2 月 12 日
In your loop
for j=2:31
dz(j)=abs(depth(j)-depth(j-1))
end
you initialize dz up to dz(31)
In
for i=1:360
for j = 1:180
for k=1:31
intFe68 = Fe68(i,j,k) *dy(360) * dx(j) * dz(j)
end
end
end
you access dz(j) with j from 1 to 180, so you need up to dz(180) to have been defined.
But notice you have k = 1 : 31 so perhaps you should be accessing dz(k) ?
  8 件のコメント
Alexandra Ridgway
Alexandra Ridgway 2017 年 2 月 13 日
Hi, yes I understand, however numeric_integral is returning NaN values only :/ Thank you for your help.
Walter Roberson
Walter Roberson 2017 年 2 月 13 日
NaN would be returned if any element in Fe68 is NaN, or if any element in the the gradients was NaN, and could be potentially be returned if there are infinities in the data.

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

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by