Sort a list of files

1 回表示 (過去 30 日間)
Kevin Gnebner
Kevin Gnebner 2019 年 6 月 21 日
コメント済み: Kevin Gnebner 2019 年 7 月 4 日
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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by