What is the meaning of A (: ,: ,1) in matlab? where A is a matrix
Show older comments
What is the meaning of A (: ,: ,1) in matlab? where A is a matrix .thanks
Accepted Answer
More Answers (1)
A(:,:,1) means: all rows and all columns of A that are in its first page.
(The third dimension is referred to in the MATLAB documentation as a "page", just as the first dimension is "row" and the second is "column").
In MATLAB all arrays can be multidimensional, and the contents can be referred to using indexing . In your example the variable A has three dimensions, and they are referred to in this way:
A(:, % all rows
:, % all columns
1) % on the first page
Although you write that A is a matrix, actually it might not be: a matrix (by definition) only has two dimensions (all higher dimensions are one), which means that if the third dimension has size two or more, then it will be an array, rather than a matrix. You might like to review matrix indexing as well.
3 Comments
bh dhouha
on 16 Feb 2015
That depends on the size of A. The behavior of mean changes depending on the size of the array that is passed to it, so you will have to tell us size(A) before we can answer that question.
If you want the mean of all elements of an array, regardless of its size or number of dimensions, then you can use mean(A(:)).
Note that mean also has an optional argument that specifies which dimensions it calculates along. We can use this for example, if A has three dimensions, to get the mean of each page using the following code:
mean(mean(A,1),2)
bh dhouha
on 16 Feb 2015
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!