For loop completing the wrong steps.

1 回表示 (過去 30 日間)
Daniel Gaggini
Daniel Gaggini 2022 年 5 月 19 日
コメント済み: Daniel Gaggini 2022 年 5 月 19 日
The aim of the code is to find the position where a event occurs (Position) and then extract the height levels (Level_Either_Side) 5 itervals before and 5 itervals after, a certain height value.
The Position code works find but the Level_Either_Side code is where the error occurs.
This is the code:
for z = 1:length(Componentry_New);
Position(z) = find(Componentry_Table == Componentry_New(z,1));
end
Level_Either_Side = [];
for p = 1:length(Componentry_New);
Level_Either_Side = [Level_Either_Side ; Sorted_Level(Position(1,p),1)-5:1:Sorted_Level(Position(1,p),1)+5];
end
The output I get is this:
46.87983 47.87983 48.87983 49.87983 50.87983 51.87983 52.87983 53.87983 54.87983 55.87983 56.87983
Which is finding the level and then subtracting or adding 1, 2, 3, 4, 5, to thefound value 51.87983., instead of extract the 5 values before and after.
Does anybody know what mistake I have made

採用された回答

Torsten
Torsten 2022 年 5 月 19 日
Level_Either_Side = [Level_Either_Side ; Sorted_Level(Position(1,p)-5:Position(1,p)+5,1)];
if 5 positions before and after exist due to the length of the array.
  1 件のコメント
Daniel Gaggini
Daniel Gaggini 2022 年 5 月 19 日
Legend!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by