why we use flag in matlab code and if we have sequence of integer then how the flag(integer)=1 ?
5 ビュー (過去 30 日間)
古いコメントを表示
intger=(2,6,8,9)
flag(intger)=1;
how it works? how flag select the value of intger
0 件のコメント
回答 (1 件)
Steven Lord
2019 年 6 月 25 日
This (note the modified first line):
intger=[2,6,8,9]
flag(intger)=1
uses linear indexing to assign to elements 2, 6, 8, and 9 of the flag array. Normally you'd want to preallocate the flag array to some known size before assigning to those specific elements. For instance, if you used the Hilbert matrix example from that blog post, you may want to make flag a logical matrix the same size as the Hilbert matrix.
A = hilb(5)
flag = false(size(A))
intger=[2,6,8,9]
flag(intger)=1
elements2_6_8_and_9 = A(flag)
Why is element 9 the element in the fourth row, second column of A rather than the second row, fourth column? MATLAB is column major. The linear order of elements in A is:
orderOfElements = reshape(1:numel(A), size(A))
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!