Requested array exceeds the maximum possible variable size.
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MatlabUser
el 24 de En. de 2021
Comentada: Walter Roberson
el 25 de En. de 2021
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 comentarios
Respuesta aceptada
Steven Lord
el 24 de En. de 2021
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 comentarios
Walter Roberson
el 25 de En. de 2021
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!