how can I test and display how many values in a vector are contained in a pre-determined interval
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
zakaria debih
el 29 de Abr. de 2019
Comentada: zakaria debih
el 30 de Abr. de 2019
%her is my vector, I want to make a script that allow to display how many elements in the interval T=[160:192] automatically, so I can later calculate the succes rate this way :
%number_of_elements_in_T * 100 / length(idx);
idx=[168 190 173 147 147 110 169 57 174 122 159 174 104 132];
1 comentario
Rik
el 29 de Abr. de 2019
Why didn't you put in your vector as text?
idx=[168 190 173 147 147 110 169 57 174 122 159 174 104 132];
Respuesta aceptada
Rik
el 29 de Abr. de 2019
Trivial with ismember:
idx=[168 190 173 147 147 110 169 57 174 122 159 174 104 132];
T=160:192;
in_T=ismember(idx,T);
number_of_elements_in_T=sum(in_T);
number_of_eliments_out_T=sum(~in_T);
%or:
%number_of_eliments_out_T=numel(idx)-number_of_elements_in_T
score = number_of_elements_in_T * 100 / number_of_eliments_out_T;
If your values in T wouldn't be integers, you should use ismembertol, if your values in idx should be in a range, you could also consider the following setup:
idx=[168 190 173 147 147 110 169 57 174 122 159 174 104 132];
T_bounds=[160 192];
in_T=idx>T_bounds(1) & idx<T_bounds(2);
3 comentarios
Rik
el 29 de Abr. de 2019
If you want to count the number of elements you can use the numel function. I would not suggest the length function, because that is generally not what you mean (a call to size with a second argument tends to solve the problems that numel can't solve).
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!