Finding cube with most Values

6 ビュー (過去 30 日間)
mfl
mfl 2019 年 8 月 12 日
コメント済み: John D'Errico 2019 年 8 月 12 日
I have a matrix with an changing amount of rows and 3 columns.First column has x, second y, third z values of a 3D-Systems. The Values may change and I want to know in wich 10x10x10 cube are the most values and what is the center of the cube.
Is there a built-in function of Matlab which can handle this or can someone give me an advice how to handle that problem?
Thanks in advance.

回答 (2 件)

John D'Errico
John D'Errico 2019 年 8 月 12 日
Why would you expect there exists built-in code to do something totally unusual like this? Built-in code is written to solve common problems. It should be something that a wide variety of users will find valuable.
You have scattered data in 3-d. The problem is, this is an optimiztion problem, but it is significanty a piecewise constant thing. That is, your objective is to maximize the count of points inside the cube. But you will be able to shift the cube by some amount in any direction (most of the time) and not change the number of elements in the cube. So your objective is a piecewise constant thing, a highly nasty thing to try to optimize. Don't even think of trying to use a general optimizer like fminsearch or fmincon/fminunc.
How would I solve it? I would discretize the problem. Create a 3-d array, where the indices are a scaled, discretized version of (x,y,z). Each element of the array is then the number of points that fell within 5 units in any direction. Do this all by a simple loop, where you increment by 1 all cells in the array in the vicinity of each point. (This can be done quite efficiiently. Learn about sub2ind, and how dfata is stored in an array in MATLAB.)
When done, just find the cell of that array that has the maximum count.

Bruno Luong
Bruno Luong 2019 年 8 月 12 日
This FEX might help
  1 件のコメント
John D'Errico
John D'Errico 2019 年 8 月 12 日
Even in 1-d, a histogram would not solve the problem, because it counts the number of elements in a fixed set of bins. The question here asks for the optimal single bin that contains the largest number of points. So if you choose the wrong edges for bins of the histogram, it will potentially miss the optimum, which may span the chosen bins.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by