Finding the index of each last field of an array that contains a value between two set values
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Gareth Pritchard
il 28 Ott 2014
Commentato: Gareth Pritchard
il 28 Ott 2014
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 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!