matlab - Get index position of where vector changes value -
i have vector contains list of strings ordered. know index number of vector changes. below clear example. not use matlab much. in head i'm thinking of using loop. wondering if there better way of doing using matlab?
vector abc abc abc abc mnk mnk mnk plo plo
so know abc 1:4, mnk 5 : 7 & plo 8 : 9
one approach -
%%// input a1 = { 'abc' 'abc' 'abc' 'abc' 'mnk' 'mnk' 'mnk' 'plo' 'plo'}; [val,x2] = unique(a1,'first'); [~,x12] = unique(a1); %%// default takes last unique value out = [val num2cell(x2) num2cell(x12)]
output -
out = 'abc' [1] [4] 'mnk' [5] [7] 'plo' [8] [9]
Comments
Post a Comment