Matlab recursively add points to a vector

조회 수: 3 (최근 30일)
Daniel ziv
Daniel ziv 2017년 5월 17일
편집: Jan 2017년 5월 19일
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
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
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
Daniel ziv
Daniel ziv 2017년 5월 17일
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 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
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.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by