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

1 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2016-2-12
编辑:Andrei Bobrov 2016-2-12
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by