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 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!