MATLAB Answers

How to distinguish two similar but different strings?

1 ビュー (過去 30 日間)
Ibro Tutic
Ibro Tutic 2017 年 6 月 28 日
編集済み: Stephen Cobeldick 2017 年 6 月 28 日
I have a function that sorts files based on file name. Two of the categories are 'Z7PR' and 'Z7PR1', which are two different tests. However, my sorting program sorts 'Z7PR' into 'Z7PR1', because it seems to match the 'Z7PR'. Is there anyway to distinguish the two without using 'Z7PR_' as I am currently doing?
Here is my code:
function otpS = filesort(inpS)
C = {'Z1P','Z2P','Z1G','Z2G','Z3K','Z4K','Z5K','Z3M','Z4M','Z5M','Z6MS','Z7PR_','Z7PR1'}; %files to find
N = {inpS.name}; %initializes structure
otpS = struct(); %initializes structure
for k = 1:numel(C)
idx = cellfun('isempty',regexp(N,C{k},'once')); %finds matching strings
otpS.(C{k}) = N(~idx); %organizes files based on C
end
end

  2 件のコメント

Image Analyst
Image Analyst 2017 年 6 月 28 日
Why not just use the sort() function?
Ibro Tutic
Ibro Tutic 2017 年 6 月 28 日
It seems I like to make things more difficult then necessary, I'll take a look at the function.

サインインしてコメントする。

回答 (1 件)

Stephen Cobeldick
Stephen Cobeldick 2017 年 6 月 28 日
編集済み: Stephen Cobeldick 2017 年 6 月 28 日
Some ideas:

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by