Sort a list of files

1 view (last 30 days)
Kevin Gnebner
Kevin Gnebner on 21 Jun 2019
Commented: Kevin Gnebner on 4 Jul 2019
Hey guys,
i have a problem to sort my files which i load with "dir".
i want to sort my list depending on three numbers.
my unsorted list looks like:
'dantec7100_Ma=01_wait_1000_ Yaw -10,00° Pitch -10,00°'
'dantec7100_Ma=01_wait_1000_ Yaw -10,00° Pitch -15,00°'
'dantec7100_Ma=02_wait_1000_ Yaw -10,00° Pitch -10,00°'
'dantec7100_Ma=02_wait_1000_ Yaw -10,00° Pitch -15,00°'
'dantec7100_Ma=01_wait_1000_ Yaw 10,00° Pitch 10,00°'
'dantec7100_Ma=01_wait_1000_ Yaw 10,00° Pitch 15,00°'
'dantec7100_Ma=02_wait_1000_ Yaw 10,00° Pitch 10,00°'
'dantec7100_Ma=02_wait_1000_ Yaw 10,00° Pitch 15,00°'
....
Ma goes from 01 to 07
Yaw goes from -20 to 20
Pitch goes from -20 to 20
I want the following sequence for all "Ma" starting from 01 to 07:
I want to start with "Ma=01". Then the lowest Yaw-Angle (-20) has to follow and to be fixed, and the pitch angles have to follow from the lowest to the highest (-20 to 20). Than increase the yaw angle to -5 and run again all pitch angle from -20 to 20, and so on for all yaw-angles. When this is ready, i want to increase "Ma" to 02 and do the same again.
i hope my problem is clear.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 21 Jun 2019
Edited: Andrei Bobrov on 21 Jun 2019
data = { 'dantec7100_Ma=01_wait_1000_ Yaw -10,00° Pitch -10,00°'
'dantec7100_Ma=01_wait_1000_ Yaw -10,00° Pitch -15,00°'
'dantec7100_Ma=02_wait_1000_ Yaw -10,00° Pitch -10,00°'
'dantec7100_Ma=02_wait_1000_ Yaw -10,00° Pitch -15,00°'
'dantec7100_Ma=01_wait_1000_ Yaw 10,00° Pitch 10,00°'
'dantec7100_Ma=01_wait_1000_ Yaw 10,00° Pitch 15,00°'
'dantec7100_Ma=02_wait_1000_ Yaw 10,00° Pitch 10,00°'
'dantec7100_Ma=02_wait_1000_ Yaw 10,00° Pitch 15,00°'};
a = regexp(data,'(\-)?\d+(,\d+)?','match');
b = regexprep(cat(1,a{:}),',','.');
[~,ii] = sortrows(str2double(b(:,[2,4,5])));
out = data(ii);
  8 Comments
Andrei Bobrov
Andrei Bobrov on 25 Jun 2019
Edited: Andrei Bobrov on 25 Jun 2019
a = regexp(data,'.*Ma=0[1-7].*Yaw\s+0,00.*Pitch\s+0,00°$','match','once');
out = a(~cellfun(@isempty,a));
or
a = regexp(data,'(\-)?\d+(,\d+)?','match');
b = regexprep(cat(1,a{:}),',','.');
M = str2double(b(:,[2,4,5]));
out = data(ismember(M(:,1),1:7) & M(:,2) == 0 & M(:,3) == 0);
Kevin Gnebner
Kevin Gnebner on 4 Jul 2019
Hey Andrei,
is it possible that i only get the indices, where the filenames with "0,00" are? as you did it in my first question.

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!