Create a 4-by-2-by-3 array of ones and compute the sum along the third dimension. [code]A = ones(4,2,3); S = sum(A,3)[/code]

Duyên Trương

New member
Create a 4-by-2-by-3 array of ones and compute the sum along the third dimension.
Code:
A = ones(4,2,3);
S = sum(A,3)
A.
S = 3 3
3 3
3 3
3 3
B.
S = 3 4
3 4
3 4
3 4
C.
S = 2 3
2 3
2 3
2 3
D.
S = 7 3
5 3
6 3
3 3
 
Answer: a
Explanation: S = sum(A) returns the sum of the elements of A along the first array dimension whose size does not equal 1. If A is a multidimensional array, then sum(A) operates along the first array dimension whose size does not equal 1, treating the elements as vectors. This dimension becomes 1 while the sizes of all other dimensions remain the same.
 

Tìm kiếm

Back
Top