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
采纳的回答
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 Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!