Sum function on part of an array
6 ビュー (過去 30 日間)
古いコメントを表示
Robert Demyanovich
2021 年 6 月 8 日
コメント済み: Walter Roberson
2021 年 6 月 8 日
I don't understand what the following sum function does.
mA=zeros(M,1);
mA(1)=sum(cA(1,:))*dx;
mA is a column vector, so what does mA(1) mean?
The documentation for the sum function indicates that taking the sum of a vector just results in one value which is the sum of all of the values in the vector. Is that also what happens when you take the sum of a single row in a matrix (sum(cA(1,:)))? So is mA(1) equal to a single value? I can't seem to find out what mA(1) means for a vector.
0 件のコメント
採用された回答
Walter Roberson
2021 年 6 月 8 日
mA(1) in this context is designating a single array element as the destination for the assignment. You are putting the results into the first box of the stack of cubby-holes.
Is that also what happens when you take the sum of a single row in a matrix (sum(cA(1,:)))
Yes.
4 件のコメント
Walter Roberson
2021 年 6 月 8 日
Right.
reshape(1:25,5,5)
reshape() changes the information about dimensions without changing the order in memory, so the values you see above in this particular case also happen to correspond to linear index.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!