Identidying next "n" elements of an array

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.

 채택된 답변

Sara
Sara 2014년 5월 13일

0 개 추천

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

James
James 2014년 5월 13일
Thank you for your answer, Sara. Can you explain to me what the second line you have written is doing? I think that I want to be:
y(Inds+1:min(Inds+n,numel(h))) = y(Inds);
If I am not mistaken. This will then identify the next n elements in my y array and set them to the value of y(Inds), correct? I am not sure what nume1(h) is.
Thanks
For instance: inds = 45; n = 10; but you have only 50 elements in y. To avoid having problems, you have to limit the max value of inds+n to the number of elements of the y array (i.e., numel(y)) as:
y(Inds+1:min(Inds+n,numel(y))) = y(Inds);
James
James 2014년 5월 13일
Great. Thank you.
José-Luis
José-Luis 2014년 5월 13일
Please accept an answer if it helped you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2014년 5월 13일

댓글:

2014년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by