all function B = all(A < 0.5,3)
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
This is straight forward to me:
A = [0.53 0.67 0.01 0.38 0.07 0.42 0.69]
B = all(A < 0.5,1)
this also makes sense -
A = [0.53 0.67 0.01; 0.38 0.07 0.42 ]
B = all(A < 0.5,2)
But why does this yield the same result?
A = [0.53 0.67 0.01 1.1; 0.38 0.07 0.42 0.01]
B = all(A < 0.5,3)
OR
B = all(A < 0.5,4)
1 comentario
Stephen23
el 15 de Jun. de 2023
Editada: Stephen23
el 15 de Jun. de 2023
"But why does this yield the same result?"
Consider the sub-arrays (i.e. vectors) along each of the specified dimensions: what values do they have in them? Remember that all arrays implicitly have infnite trailing singleton dimensions: the fact that each of those vectors for dimensions 3 and 4 happen to have one element in them is irrelevent, ALL applies its algorithm on that one element. It might help to revise this: https://www.mathworks.com/help/matlab/math/multidimensional-arrays.html
Lets consider the top left corner of your data:
A = [0.53 0.67 0.01 0.38 0.07 0.42 0.69];
A(1,1,:) % top left, all elements along 3rd dimension
A(1,1,1,:) % top left page1, all elements along 4th dimension
You can repeat this yourself for every other element in your matrix.
Question: what do you expect the result to be? Why?
Respuestas (2)
the cyclist
el 14 de Jun. de 2023
Editada: the cyclist
el 14 de Jun. de 2023
The reason is that all MATLAB arrays have implied singleton dimension beyond the 2nd dimension, if they have not been actually specified.
A = [0.53 0.67 0.01 1.1;
0.38 0.07 0.42 0.01];
size(A,47)
0 comentarios
Torsten
el 14 de Jun. de 2023
Movida: Torsten
el 14 de Jun. de 2023
But why does this yield the same result?
Because A has only 2 dimensions, not 3 or 4. Thus "all" operates on all elements separately in both cases.
1 comentario
VBBV
el 15 de Jun. de 2023
Thus "all" operates on all elements separately in both cases., Yes, thats correct. But if one uses 'all' option it would do only once.
A = [0.53 0.67 0.01 1.1; 0.38 0.07 0.42 0.01]
B = all(A < 0.5,'all')
B = all(A < 0.5,3)
B = all(A < 0.5,4)
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations 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!