Monday, 15 August 2011

string - Deleting rows depending on two conditions - Matlab -



string - Deleting rows depending on two conditions - Matlab -

i have cell-type variable in matlab alphabetically organized firm.to each firm correspond different , repeated c1s , c2s. each firm delete repeated c2s (and respective row). method take row d2 that's furthest d1.

initial cell:

firms c1 c2 d1 d2 d3 'acro' '01464''043605' '19961231''19970212''19970401' 'acro' '01464''043605' '19961231''19970119''19970313' 'acmj' '00118''043605' '19961231''19970114''19970219' 'acmj' '01464''000151' '19961231''19970121''19970218' 'acmj' '00192''007960''19961231''19970523''19970728'

final cell:

'acro' '01464''043605' '19961231''19970212''19970401' 'acmj' '00192''007960''19961231''19970523''19970728'

can help me? lot in advance.

try this

a = initial_cell; b = (abs(str2num(cell2mat(a(:,4))) - str2num(cell2mat(a(:,5))))); [temp ind1] = sort(b); s = a(ind1(end:-1:1),:); [temp1 ind2 temp2] = unique(strcat(s(:,1),s(:, 3))); out_cell = s(ind2,:);

output is

out_cell = 'acmj' '01464' '000151' '19961231' '19970121' '19970218' 'acmj' '00192' '007960' '19961231' '19970523' '19970728' 'acmj' '00118' '043605' '19961231' '19970114' '19970219' 'acro' '01464' '043605' '19961231' '19970119' '19970313'

note out_cell sorted firm in output, while not sorted firm in output stated in question. notify me if need way.

string matlab cell condition

No comments:

Post a Comment