Matlab recursively add points to a vector

3 visualizzazioni (ultimi 30 giorni)
Daniel ziv
Daniel ziv il 17 Mag 2017
Modificato: Jan il 19 Mag 2017
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 Commento
Jan
Jan il 17 Mag 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.

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 17 Mag 2017
Modificato: Matt J il 17 Mag 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 Commenti
Daniel ziv
Daniel ziv il 17 Mag 2017
actually it seems very possible if i locally threshold my cells to turn them into binary and then use connected_components and then check if my seed hits the connected component. I find it hard to find all the methods nessasary if its simple enough can u plz help me with those few lines of code?
Image Analyst
Image Analyst il 19 Mag 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.

Accedi per commentare.

Più risposte (1)

Jan
Jan il 17 Mag 2017
Modificato: Jan il 19 Mag 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.

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by