why we use flag in matlab code and if we have sequence of integer then how the flag(integer)=1 ?
7 次查看(过去 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!