Hi.
I have filename is string and then I want to find specific name.
if filename have ' a ' xxx = 1
if filename have ' b ' xxx = 2
if filename have ' c ' xxx = 3
thank you.

7 件のコメント

Jan
Jan 2019 年 4 月 9 日
Please explain more details. What does "filename have ' a '" mean? Start with an 'a' or contain an 'a' anywhere?
if filename(1) == 'a'
or
if any(filename == 'a')
Jassy
Jassy 2019 年 4 月 9 日
Thank you for your assistance.
"filename have ' a '" mean?
I mean filename is #####a .jpg
Adam Danz
Adam Danz 2019 年 4 月 9 日
編集済み: Adam Danz 2019 年 4 月 9 日
So these are all =1?
  • aaaaa.jpg
  • axxxx.jpg
  • a.jpg
What about this?
  • xxA.jpg (capital letter
  • xxxx.app (file extension)
Jan
Jan 2019 年 4 月 9 日
With the space between the "a" and the ".jpg"? What should happen for "b#####a .jpg"? Is "#" a digit? Please do not let the readers guess the details.
Jassy
Jassy 2019 年 4 月 9 日
All filename is not have a,b,c in the same file.
Ex. Z1q0001a , Z2q0002a
Z1q0001b , Z2q0002b
Z4f0001c , Dsf0002c
and not have
  • xxA.jpg
  • xxxx.app
because all filename have a,b,c each file.
Adam Danz
Adam Danz 2019 年 4 月 9 日
編集済み: Adam Danz 2019 年 4 月 9 日
what if filename has 'a' and 'b' what value does it get?
This question needs to be defined more clearly.
Adam Danz
Adam Danz 2019 年 4 月 9 日
So, it's always the last letter of the filename?

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

 採用された回答

Jan
Jan 2019 年 4 月 9 日

1 投票

Maybe:
[fPath, fName, fExt] = fileparts(filename);
if endsWith(fName, 'a ') % With the space as in your example
xxx = 1;
elseif endsWith(fName, 'b ')
xxx = 2;
... etc
end
Or:
[fPath, fName, fExt] = fileparts(filename);
switch fname(end-1) % Again assuming you mean the 2nd last character
case 'a'
xxx = 1;
case 'b'
xxx = 2
... etc
otherwise
error('Unexpected charatcer')
end

1 件のコメント

Jassy
Jassy 2019 年 4 月 9 日
Thank you so much. It saved me
and next time I will give detail more than this.

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

その他の回答 (1 件)

Adam Danz
Adam Danz 2019 年 4 月 9 日

0 投票

The cell array 'key' lists all possible last-characters and the order determines the value.
filename = 'Z2q0002b.jpg';
[~, fName] = fileparts(filename);
key = {'a' 'b' 'c'};
xxx = find(strcmp(key, fName(end)));
xxx =
2

カテゴリ

ヘルプ センター および File ExchangeThermal Analysis についてさらに検索

タグ

質問済み:

2019 年 4 月 9 日

コメント済み:

2019 年 4 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by