adding index to matrix rows
Mostrar comentarios más antiguos
I have a matrix like this
1 0
0 2
2 1
0 3
3 2
2 0
4 1
1 6
6 4
6 1
I would like to have the following matrix, please help me if you have the answer.
0: 1 0
1: 0 2
2: 2 1
3: 0 3
4: 3 2
5: 2 0
6: 4 1
7: 1 6
8: 6 4
9: 6 1
Respuesta aceptada
Más respuestas (1)
Renato Agurto
el 27 de Mayo de 2016
Editada: Renato Agurto
el 27 de Mayo de 2016
Is this what you want? Or what do you mean with ':' in a matrix?
A = [1 0;
0 2;
2 1;
0 3;
3 2;
2 0;
4 1;
1 6;
6 4;
6 1];
B = [(0:size(A,1)-1)' A];
2 comentarios
Ali
el 27 de Mayo de 2016
Allison Chua
el 6 de Oct. de 2020
@Renato Agurto - thank you SO much!!! I'm so terrible at Matlab syntax, and this was exactly what I needed.
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!