Matlab recursively add points to a vector
3 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a 3d matrix and i wish to create a function that looks at its enviroment and if a point in that enviroment satisfies a condition i want to add it to my vector. then use the function on that point to see if it also satisfies and so on. my idea was to preform a recursive function that calls itself on the next point that satisfies the condition. the only problem is that for every point i add to the vector Matlab would copy the entire vector array, this will slow me down incredibly as that vector is incredibly large, from what i understand passing a pointer to the array is impossible in matlab so im confused as to how am i to do it?
my question is mostly how do i pass an array of vectors as pointer so that matlab keeps feeling it instead of re-creating it over and over again.
1 件のコメント
Jan
2017 年 5 月 17 日
I do not understand the detail concerning "looks at its environment". What does this mean? What exactly is a "vector array"? A matrix? Matlab uses a copy-on-write strategy, such that you do not create a deep data copy, when a variable is provided as input to a function. Only the iterative growing of arrays is a problem. Terms like "incredibly large" are not useful in a scientific discussion. Some people are impressed by 10'000 elements already, because they cannot add them manually anymore. Other users run Matlab on huge TB cluster machines.
採用された回答
Matt J
2017 年 5 月 17 日
編集済み: Matt J
2017 年 5 月 17 日
I would recommend a different approach entirely. I would first evaluate every voxel (i,j,k) in the array to see if it satisfies the condition. This will give you a 3D binary map BW. Then, I would use bwconncomp or regionprops in the Image Processing ToolBox to find the groups of 'on' voxels in BW that are connected through a chain of neighbors.
There are many possible variations on this idea that could be applicable if you give a more detailed description of the task.
3 件のコメント
Image Analyst
2017 年 5 月 19 日
You forgot to attach the image. Even a 2-D slice would help me to understand. I'm inclined to agree with Matt J so far, but then, we haven't seen your image yet.
その他の回答 (1 件)
Jan
2017 年 5 月 17 日
編集済み: Jan
2017 年 5 月 19 日
See Lorens Blog: Inplace operations . Maybe your assumption is wrong, that Matlab copies the "vector array" (what ever this means) in each call of a function. If you explain, how many elements "incredibly large" is, one could estimate, if a cell array is a useful solution for you. So please add more details and explain, why you think that the memory management is the bottleneck of your code.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!