Identidying next "n" elements of an array

3 visualizaciones (últimos 30 días)
James
James el 13 de Mayo de 2014
Comentada: José-Luis el 13 de Mayo de 2014
I am working on a coastline evolution model. What I would like to do is identify the element(s) in my water depth array that satisfy a certain condition. For instance find(h<.90 & h>0.89). I would then like to identify the next "n" values in my "y" (coastline height) array that have values greater than the located element(s)and set all of their values equal to the y value of the array elements where the find(h<.90 & h>0.89) condition was met. Hopefully this makes sense. I'll try and sum it up...
I HAVE:
ymax = 20 ymin = 200 y = ymin:0.02:ymax x = (y+20)/0.02
Sealevel = (very long array)
h = y-Sealevel
I WANT:
Inds = find(h<.90 & h>0.89)
%then take that element(s) location and find it in my y array, take the next "n" elements in the y array and make their value the same value of the y value of "Inds" element
I am not sure how to deal with Inds returning multiple elements. Ideally I would just like it to find the first elements that satisfies the condition.

Respuesta aceptada

Sara
Sara el 13 de Mayo de 2014
To find just the first element that meets your condition, you can do:
Inds = find(h<.90 & h>0.89,1);
then:
h(Inds+1:min(Inds+n,numel(h))) = h(Inds);
  4 comentarios
James
James el 13 de Mayo de 2014
Great. Thank you.
José-Luis
José-Luis el 13 de Mayo de 2014
Please accept an answer if it helped you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by