Finding multiple values in matrix

조회 수: 2 (최근 30일)
Thang  Le
Thang Le 2013년 3월 12일
Hi,
I have an fMRI scan file with activation values of voxels (voxels can be located by specific coordinates). Let's say v is the 72x72x33 matrix representing information from the scan file. I can easily find a single value for a given combination of coordinates. For instance, v(x1,y1,z1) would give me the value of the voxel at location (x1,y1,z1). However, the challenge is that I need to get the mean value of multiple voxels. Let's say A (3x250 matrix) represents all the voxel coordinates of interest (so there are 250 voxels total). Could you please tell me how to get the average value of all these 250 voxels from v?
Many thanks!
  댓글 수: 1
Image Analyst
Image Analyst 2013년 3월 15일
I'd probably try using meshgrid to make a list of all possible voxel coordinates and then binarize that with the equation for a sphere. Then sum up the image inside the binary image.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2013년 3월 12일
편집: Image Analyst 2013년 3월 12일
theSum = 0;
count = 0;
for k = 1:size(A, 2)
theSum = theSum + v(A(1, k), A(2, k), A(3, k));
count = count + 1;
end
theMeanIntensity = theSum / count
Even though it's a for loop, it will be very fast with only 250 iterations. If you do want to try the vectorized (linear indexing) method, you can see the help on sub2ind:
linearInd = sub2ind(arraySize, dim1Sub, dim2Sub, dim3Sub, ...) returns the linear index equivalents to the specified subscripts for each dimension of an N-dimensional array of size arraySize. The arraySize input is an n-element vector that specifies the number of dimensions in the array. The dimNSub inputs are positive, whole number scalars or vectors that specify one or more row-column subscripts for the matrix.
though there may not be much, if any, noticeable speed up.

추가 답변 (3개)

Bart Boesman
Bart Boesman 2013년 3월 12일
편집: Bart Boesman 2013년 3월 12일
Hi,
'Logical indexing' (<http://www.mathworks.nl/help/matlab/math/matrix-indexing.html#bq7egb6-1>) and 'sum() or mean()' should get you on the right track, I guess.
Bart

Thang  Le
Thang Le 2013년 3월 12일
You guys are brilliant! Thank you for the quick responses.

Thang  Le
Thang Le 2013년 3월 15일
Hi,
I have a follow-up question. Since matrix A is actually a sphere, depending on its center and radius, some of this sphere may lie outside of v, in which case an error occurs when a voxel space outside of v is accessed. Is there any way I can get the mean for only valid values?
A rough solution I thought of was to get the values in 250-by-1 matrix (each row is an activation value from v corresponding to the same row of coordinates in A), then use nanmean to exclude the NaN's from the mean. However, I'm not sure how to get this 250x1 matrix from the code you suggested. Could you help?
Thanks,
Le

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by