Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

which two members from s vector restricted a random number

1 visualización (últimos 30 días)
som
som el 3 de Sept. de 2012
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi all,
I have a vector like s=[200 278 434 590 746 903 1059 1215 1371 1450]. I want to determine which two members from s vector restricted a random number like b=300 ? for example 300 is between 278 and 434.
How can I write such program?
thanks in advance,

Respuestas (1)

Jan
Jan el 3 de Sept. de 2012
Editada: Jan el 3 de Sept. de 2012
s = [200 278 434 590 746 903 1059 1215 1371 1450];
b = 300;
[dummy, index] = histc(b, s);
Or:
index = find(s < b, 1, 'last'); % or <= ?
Because the values of s are sorted, it is enough to find one index.

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by