Hi, I want to write a code that locates the nth value of matrix x= [2,4,6,8,10,12,14,16,18,20] where n is [1:10]. How could I write that?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Melecia Senior
el 13 de Abr. de 2021
Respondida: Steven Lord
el 13 de Abr. de 2021
Hi, I want to write a code that locates the nth value of matrix x= [2,4,6,8,10,12,14,16,18,20] where n is [1:10]. How could I write that?
0 comentarios
Respuesta aceptada
Atsushi Ueno
el 13 de Abr. de 2021
>> x= [2,4,6,8,10,12,14,16,18,20];
>> x(1:10)
ans =
2 4 6 8 10 12 14 16 18 20
>> n=[1:10];
>> x(n)
ans =
2 4 6 8 10 12 14 16 18 20
0 comentarios
Más respuestas (1)
Steven Lord
el 13 de Abr. de 2021
That's basic linear indexing. See the "Indexing with a Single Index" section on this documentation page for more information.
x = 2:2:20
n = 1:5
y = x(n)
z = x(3:8)
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing 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!