Clear Filters
Clear Filters

Finding the index of each last field of an array that contains a value between two set values

1 view (last 30 days)
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

Accepted Answer

David Young
David Young on 28 Oct 2014
It may be that you just need to use & instead of &&.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!