Effacer les filtres
Effacer les filtres

How to assign index to array

1 vue (au cours des 30 derniers jours)
Mekala balaji
Mekala balaji le 16 Sep 2017
Modifié(e) : per isakson le 16 Sep 2017
Hi,
I have data and want to assign the index to the data as below:
Input data:
col1 col2 col3 col4
1 3 4 9
3 5 5 7
4 6 11 7
0 3 7 2
I want to assign the index as the size of the data, here the size(rows) of the data is 4, then I want to add a column to assign the serial number as below:
Modified data(added 5th column):
1 3 4 9 1
3 5 5 7 2
4 6 11 7 3
0 3 7 2 4

Réponse acceptée

per isakson
per isakson le 16 Sep 2017
Modifié(e) : per isakson le 16 Sep 2017
Try
>> M(:,end+1) = reshape( [1:size(M,1)], [],1 );
>> M
M =
1 3 4 9 1
3 5 5 7 2
4 6 11 7 3
0 3 7 2 4
reshape may be replace by a blip
>> M(:,end+1) = [1:size(M,1)]';

Plus de réponses (0)

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by