Effacer les filtres
Effacer les filtres

Hi, I want to write a code that locates the nth value of matrix x= [2,4,6,8,1​0,12,14,16​,18,20] where n is [1:10]. How could I write that?

1 vue (au cours des 30 derniers jours)
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?

Réponse acceptée

Atsushi Ueno
Atsushi Ueno le 13 Avr 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

Plus de réponses (1)

Steven Lord
Steven Lord le 13 Avr 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
x = 1×10
2 4 6 8 10 12 14 16 18 20
n = 1:5
n = 1×5
1 2 3 4 5
y = x(n)
y = 1×5
2 4 6 8 10
z = x(3:8)
z = 1×6
6 8 10 12 14 16

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by