why we use flag in matlab code and if we have sequence of integer then how the flag(integer)=1 ?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
intger=(2,6,8,9)
flag(intger)=1;
how it works? how flag select the value of intger
0 comentarios
Respuestas (1)
Steven Lord
el 25 de Jun. de 2019
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 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!