Finding the index of each last field of an array that contains a value between two set values
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a 'kp' as one of the last fields of a structure (which is an array consisting of the same number, repeated) and have been using the following
kpindx=1;
kpdta = [];
for kpval = 1 : length(s)
x =s(kpval).L.kp<=20;
if sum(x) == length(s(kpval).L.kp)
kpdta(kpindx) = kpval;
kpindx = kpindx +1;
end
end
s being my structure and kpdta being the output I want - an array containing the index numbers of s where kp<=20. I have been using this to give me the indices of which values of 'kp' are less than or equal to 20. Similarly, I have used it to give me the indices of each instance of s which contains a kp > 60. I want to adapt this to give me the indices of every instance of s that gives me the indices of every instance of s where 'kp' is greater than 20 but less than or equal to 20. I tried changing line 4 to
x =s(kpval).L.kp<=20 && s(kpval).HL.kp<=60
and unsurprisingly, this didn't work. If anyone could point me in the right direction, I'd be really greatful
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!