フィルターのクリア

Reading values across an array

1 回表示 (過去 30 日間)
Amavi Silva
Amavi Silva 2021 年 7 月 5 日
コメント済み: Amavi Silva 2021 年 7 月 7 日
I am trying to run an ecosystem model for the surface ocean which is forced by entrainment and detrainment of materials by the monthly changes of the Mixed Layer Depth (MLD). I have.....
MLD = [125;160;196;50;28;23;19;24;29;48;60;100]
.......for the 12 months of the year. I am planning to use an if statement to find the new concentration of the element after the entrainment/detrainment. For an example, I want to say....
if MLD(i+1) > MLD (i)
use the entrainment equation
Else if
use the detrainment equation
Nevertheless, I am not sure I know how to restructure my MLD array so that matlab can identifiy what is the (i)th value and what is the (i+1)th value at each step. I would be so grateful if anybody can help me sort this out.
Thank you so much in advance.

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 7 月 5 日
The position of each element in an array is the element's index. The element can be retrieved for operations, such as relational comparisons as in your example, by using the index in parentheses after the name of the array. I suggest you review Array Indexing for further details and examples.
For your problem, here's how to set things up using a for-loop:
MLD = [125;160;196;50;28;23;19;24;29;48;60;100];
for i=2:length(MLD)
if MLD(i) > MLD(i-1)
% use entrainment equation here
else
% use detrainment equation here
end
end
  1 件のコメント
Amavi Silva
Amavi Silva 2021 年 7 月 7 日
Thank you so much. It did work!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by