How can I check if a value in one array is in between two values in another array?

I have an an array of random values and an array of positions. I need to check if the random values fall between two positions, but it needs to be in between values like a1 a2, a3 a4, a5 a6, it cannot be in between a2 a3, a4 a5, etc. Please let me know how to do this! I was going to use the find() function but I'm not sure how to get it to check these values.

回答(1 个)

You want to discretize your data?
edges = 0:2:10;
sampleData = 10*rand(10, 1);
whichBin = discretize(sampleData, edges);
left = edges(whichBin).';
right = edges(whichBin+1).';
results = table(sampleData, whichBin, left, right, ...
'VariableNames', {'Value', 'BinNumber', 'LeftEdge', 'RightEdge'})

类别

帮助中心File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by