Search code examples
matlabvectorrowindices

Indices of a matrix


I can't seem to get the indices of UnseenTestdata and Testdata from fulldata in the example below, can anyone help?

pointsToPick = 49402;  %# Numbers to pick
rVec = randperm(494021);   %# Random permutation of datapoint indices (N=494021 in this case)  

UnseenTestdata = fulldata(rVec(1:pointsToPick),:); %# Random sample
Testdata = fulldata(rVec((pointsToPick+1):length(rVec)),:);

I need to have a list of the row numbers from fulldata that unseentestdata came from and the same with testdata. This relates to a previous question here, without the indices I cant figure out which classlabels go with the unseentestdata and the testdata.


Solution

  • If you don't want to use rVec(1:pointsToPick) which already stores the indices as @Tobold said, the other way is

    [~,indx_uns]=ismember(UnseenTestdata, fulldata, 'rows');
    [~,indx_test]=ismember(Testdata, fulldata, 'rows');
    

    Note that the first return parameter is not used (thus marked by ~).
    indx_uns(n) gives the corresponding row of fulldata to the n-th row of UnseenTestdata.

    Moreover here is a link to the related SO question.

    For more help on ismember: see this link