フィルターのクリア

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

採用された回答

David Young
David Young 2014 年 10 月 28 日
It may be that you just need to use & instead of &&.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by