Hello, I have a string array that has been sorted but puts 10 next to 1
b = 1×6 string array "1" "10" "3" "5" "7" "r1"
My strings are upto 12.
I want the last element to remain where it is, and to move any strings > 9 if exist to the end -1
i.e.
"1" "3" "5" "7" "10" "r1"
and if I have
"1" "10" "12" "5" "7" "r1"
then to be
"1" "5" "7" "10" "12" "r1"
This is my attempt:
b Id10 = find(contains(b,"10")) if Id10>0 e=b(Id10); b(Id10)=[]; b(end-1)=e; out{j,1}=b; b end Id11 = find(contains(b,"11")) if Id11>0 e=b(Id11); b(Id11)=[]; b(end-1)=e; out{j,1}=b; b end Id12 = find(contains(b,"12")) if Id12>0 e=b(Id12); b(Id12)=[]; b(end-1)=e; out{j,1}=b; end b
but it seems to be over writing the end-1 element
b = 1×7 string array "1" "10" "11" "12" "3" "6" "r1"Id10 = 2b = 1×6 string array "1" "11" "12" "3" "10" "r1"Id11 = 2b = 1×5 string array "1" "12" "3" "11" "r1"Id12 = 2b = 1×4 string array "1" "3" "12" "r1"
Thanks for any help
Best Answer