For loop completing the wrong steps.

1 visualización (últimos 30 días)
Daniel Gaggini
Daniel Gaggini el 19 de Mayo de 2022
Comentada: Daniel Gaggini el 19 de Mayo de 2022
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

Respuesta aceptada

Torsten
Torsten el 19 de Mayo de 2022
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.

Más respuestas (0)

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by