find a rows in matrix and its position in that matrix ?

1 view (last 30 days)
%I had a matrix of size(48*6) and then
ii = randperm(size(datasheet,1));
k = ones(24,1)*2;
out = mat2cell(datasheet(ii(1:sum(k)),:),k,size(datasheet,2));
%then i select a row from datasheet lets say 4th row
%now I want to find out the position of that 4th row in "out" matrix.

Accepted Answer

Walter Roberson
Walter Roberson on 22 Nov 2017
out{ ceil( find(ii == 4)/2 ) }
MUKESH KUMAR on 12 Dec 2017
If I have updated K and datasheet values like attached file then I did not find according to this code and I also tried Index/find but did not get

Sign in to comment.

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 22 Nov 2017
Edited: Andrei Bobrov on 22 Nov 2017
In general case:
[~,ji] = cellfun(@(x)ismember(B,x,'rows'),out,'un',0);
jj_cell = find(cellfun(@(x)x>0,ji));
ii_row_in_cell = ji{jj_cell};


Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!