Find repeated row from col1,check for different values in the related rows and move it to new columns

1 view (last 30 days)
Hi all, I have a 7 x 8 cell of data and in the first column there are some repeated values. With those repeated values I'd like to find the different values in the related rows and move it to a new columns then rid repeated rows .
Any help with this would be appreciated greatly.
sample data:
[1] [ 1] 'as' 'vps' 'O363' 'hpv'
[2] [ 7] 'ps' 'kp' 'O321' 'pp'
[2] [ 7] 'ps' 'kp' 'O342' 'jd'
[3] [15] 'v' 'z' 'O363' 'hpv'
[3] [15] 'v' 'z' 'O342' 'jd'
[3] [ 2] 'ep' 'z' 'O363' 'hpv'
[3] [ 2] 'ep' 'z' 'O342' 'jd'
I have matlab file attached... I tried
for ii =1:6
if(sample{ii,1}) ==sample{ii+1,1},
for j = 2:8,
if isequaln(sample(ii+1,j),sample(ii,j)),
else
add_co(ii,j)= sample(ii+1,j)
end
end
end
end
Thanks a lot for any help.
-ibrahim
  3 Comments
bero
bero on 12 Feb 2016
Edited: bero on 12 Feb 2016
what I need is in ask.m file. My original matrix is about 50000x75,the above is a sample only...

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 12 Feb 2016
Edited: Andrei Bobrov on 12 Feb 2016
s = {[1] [ 1] 'as' 'vps' 'O363' 'hpv'
[2] [ 7] 'ps' 'kp' 'O321' 'pp'
[2] [ 7] 'ps' 'kp' 'O342' 'jd'
[3] [15] 'v' 'z' 'O363' 'hpv'
[3] [15] 'v' 'z' 'O342' 'jd'
[3] [ 2] 'ep' 'z' 'O363' 'hpv'
[3] [ 2] 'ep' 'z' 'O342' 'jd' }
s1 = [s{:,1}]';
s(:,2) = cellfun(@num2str,s(:,2),'un',0);
s11 = unique(s1);
t = max(histc(s1 ,s11));
n = numel(s11);
out0 = cell(n,t);
for jj = 1:n
k = s11(jj) == s1;
z = s(k,2:end)';
uu = unique(z(:),'stable');
out(jj,1:numel(uu)+1) = [{s11(jj)};uu];
end
  3 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Large Files and Big Data 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!