Find repeated row from col1,check for different values in the related rows and move it to new columns
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 12 Feb. 2016
Bearbeitet: Andrei Bobrov
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!