Requested array exceeds the maximum possible variable size.
21 次查看(过去 30 天)
显示 更早的评论
I am trying to get the mean value of all pixels in 5D array (arr):
let (f) a 4D array that I want to search for a value in it:
size of arr= (800,800,3,9,9)
size of f = (800,800,9,9)
[x, y, z, w] = ind2sub(size(f),find(f == value));
result = mean(arr(x, y ,3, z ,w),'all');
I receive this error :
Requested array exceeds the maximum possible variable size. when using mean!
any help is appreciated,
thanks
0 个评论
采纳的回答
Steven Lord
2021-1-24
Let's say you want to extract the two elements equal to 1 in this matrix.
A = [1 2 3; 4 5 6; 7 8 1]
You can do this with find and ind2sub.
locations = find(A == 1)
[row, col] = ind2sub(size(A), locations)
Now let's extract the 1's from A.
B = A(row, col)
Why are the 3 and 7 in there? Because B contains all the elements at the intersections of rows in the variable row and columns in the variable col. So even though you may have expected B to have only two elements because row and col each had two elements, it actually has two times two or four elements.
Now let's look at a slightly different matrix:
C = [1 1 3; 4 5 6; 7 8 1];
locationsC = find(C == 1);
[rowC, colC] = ind2sub(size(C), locationsC)
D = C(rowC, colC)
These are the elements at the intersections of rows 1, 1, and 3 and columns 1, 2, and 3. Given that knowledge, even though arr is of size (800,800,3,9,9) the array arr(x, y ,3, z ,w) may be much larger.
If you just want the mean of elements in an array corresponding to locations of a specific value in another array, don't use subscripted indexing. Use logical indexing.
justThreeElements = A(C == 1)
mean(justThreeElements)
The fact that you have that other dimension in arr is a little tricky, but you could extract just the third page to a separate variable.
3 个评论
Walter Roberson
2021-1-25
Yes. It has to do with how indexing works, and the indexing is done before the outer function such as sum() or mean() is called.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!