## How to reduce the time of calculation for a matrix with size of 24 million by 8 ?

on 12 Feb 2013

### Matt J (view profile)

Hi,
I have a matrix of size 24,000,000 x 8 with integer numbers, for example consider this;
a=[...
34600 34602 33576 33574 297769 297771 296745 296743
34601 34603 33577 33575 297770 297772 296746 296744
34602 34604 33578 33576 297771 297773 296747 296745
34603 34605 33579 33577 297772 297774 296748 296746
34604 34606 33580 33578 297773 297775 296749 296747
34605 34607 33581 33579 297774 297776 296750 296748
34606 34608 33582 33580 297775 297777 296751 296749
34607 34609 33583 33581 297776 297778 296752 296750
34608 34610 33584 33582 297777 297779 296753 296751]
I wanna renumber its member such that the member with minimum amount become 1 and it continues renumbering till reach to maximum member:
member=reshape(a,(size(a,1)*size(a,2)),1);
member=unique(member);
member=sortrows(member);
Newmember=(1:size(member,1))';
renFun=@(x) Newmember(member==x);
Renumbered_a=arrayfun(renFun,a);
It takes too much time to finish the procedure for 24 million rows. Any suggestion to reduce the time of calculation?
Arash

Jan

### Jan (view profile)

on 12 Feb 2013
After calling unique, you overwrite the answer in the next line already. Therefore this wastes time only.
Arash

on 12 Feb 2013

on 12 Feb 2013
Edited by Matt J

### Matt J (view profile)

on 12 Feb 2013

[~,~,Renumbered_a]=unique(a(:));
Renumbered_a=reshape(Renumbered_a,size(a));

Arash

### Arash (view profile)

on 12 Feb 2013
Thank you Matt, it was awesome.