For loop completing the wrong steps.

조회 수: 16 (최근 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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by