Filter löschen
Filter löschen

For Loop induced matrix manipulation , Relative index matrix

1 Ansicht (letzte 30 Tage)
>> a =[1,2,3,0,0,0,0,8,9,0,11,0,0,14,15];
So i have a big matrix and i want to make another matrix b such that it gives me the relative number index(by this what i mean is it gives me the index of representative number next to the matrix a element ) of matrix a.
i tried a for loop but didnt work to what i wanted...
for eq number 15 present in matrix a is the 8th number present(rest are zeroes) in the whole matrix a
%%%%%%%%%%%%%%% DESIRED OUTPUT %%%%%%%%%%%
[a' b']
ans =
1 1
2 2
3 3
0 0
0 0
0 0
0 0
8 4
9 5
0 0
11 6
0 0
0 0
14 7
15 8

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 23 Nov. 2011
[tf, b] = ismember(a, a(a ~= 0));
[a' b']

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by