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
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!