Matlab recursively add points to a vector
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Jan
am 17 Mai 2017
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.
Akzeptierte Antwort
Matt J
am 17 Mai 2017
Bearbeitet: Matt J
am 17 Mai 2017
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 Kommentare
Image Analyst
am 19 Mai 2017
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.
Weitere Antworten (1)
Jan
am 17 Mai 2017
Bearbeitet: Jan
am 19 Mai 2017
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 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!