Filter löschen
Filter löschen

checking an interval by using switch case function

4 Ansichten (letzte 30 Tage)
Cem Eren Aslan
Cem Eren Aslan am 2 Dez. 2021
Beantwortet: Steven Lord am 2 Dez. 2021
Hello everyone,
I'm trying to find the range of a number by using the switch-case function. How can I find this number? In other words, let's say we have three intervals, 10-50, 50-70, 70-100. If our input is 15, how can I insert it into the first case by using switch case function?

Akzeptierte Antwort

Steven Lord
Steven Lord am 2 Dez. 2021
switch and case are not the best tools for this application, at least not alone. If you have a small number of potential cases either use if and elseif or use discretize to bin the continuous values into discrete bin numbers and then use switch and case on those discrete bin numbers.
x = randi([10 100], 1, 5)
x = 1×5
22 40 65 79 73
d = discretize(x, [10 50 70 100])
d = 1×5
1 1 2 3 3

Weitere Antworten (0)

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by