For loop completing the wrong steps.

1 次查看(过去 30 天)
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by