Sort a list of files

1 次查看(过去 30 天)
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.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2019-6-21
编辑:Andrei Bobrov 2019-6-21
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 个评论
Andrei Bobrov
Andrei Bobrov 2019-6-25
编辑:Andrei Bobrov 2019-6-25
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 2019-7-4
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by