Matrix(Matrix)
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Prabhat Hegde
el 10 de Abr. de 2020
Respondida: nada zaidi
el 6 de Abr. de 2021
I am a new MATLAB user and am unsure of what operation is being carried out by the below chunk of code.
a=[1 1;1 2]
b=[1;0;0;1]
b(a(:),:)
ans =
1
1
1
0
a(:)
^obviously gives the column vector of a.
(a(:),:)
^selects all rows and columns in this column vector.
b(a(:),:)
^what does this chunk of code do?
0 comentarios
Respuesta aceptada
James Tursa
el 10 de Abr. de 2020
Editada: James Tursa
el 10 de Abr. de 2020
The "a" values are simply being used as row numbers for indexing into b.
b(a(:),:)
= b([1;2;1;2],:)
which is equivalent to
[ b(1,:);
b(2,:);
b(1,:);
b(2,:)]
=
1
0
1
0
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!