Assignment of values in an empty matrix by logical indices
4 ビュー (過去 30 日間)
古いコメントを表示
I have the following behavior but I expected another one:
>> H=zeros(3,0)
H =
Empty matrix: 3-by-0
>> H(3,false)=1
H =
Empty matrix: 3-by-0
>> H(4,false)=1
H =
Empty matrix: 4-by-0
It seems the value is not assigned but the matrix dimension is extended. Maybe someone is able to explain this behavior.
Thanks Stefan
0 件のコメント
回答 (3 件)
David Sanchez
2014 年 1 月 8 日
matlab start indexing arrays with 1. Arrays in Matlab do not have element in position 0.
H(3,false) = H(3,0)
what does not exist: you do not change anything with that line.
H(4,false) add an extra row to the original matrix but does not assign a value to its elements since H(4,0) is not an element.
0 件のコメント
Jos (10584)
2014 年 1 月 8 日
For a matrix M, and scalars R, C and V, the expression
M(r,c) = V
means that you want to set the value of the Rth row and Cth column of the matrix M to the value V. If that row or column does not exist, create it.
For a logical vector TF
M(r,TF) = V
means to set the elements of the Rth row and the columns where TF is true to the value V. Again, if row R does not exist, create it.
So, the following makes sense:
A = 2, A(2,3) = 4
B = zeros(2,0), B(3,[false true false]) = 99
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!