dir([num2str(d) '\*.png']

dir([num2str(d) '\*.png']
Any one can tell me what is happening over here?

回答 (1 件)

Stephen23
Stephen23 2018 年 6 月 29 日
編集済み: Stephen23 2018 年 6 月 29 日

0 投票

It searches for files name with the file extension .png that are located in the directory d.
dir([num2str(d) '\*.png']
'\*.png' % character vector
num2str(d) % convert |d| to character
[ ] % horizontally concatenate the two character vectors
dir( ) % call DIR
Better would be to use fullfile:
dir(fullfile(num2str(d),'*.png'))

3 件のコメント

Shanuka Jayasinghe
Shanuka Jayasinghe 2020 年 4 月 14 日
編集済み: Shanuka Jayasinghe 2020 年 4 月 14 日
errr no... i got something else utilizing that code.
for the case where d = 'string'
it searches for files in the current directory that match the file name 'string*.png'
Here's what I got in my command window when i pasted the above code with d = 'string'
>> d = 'string'
d =
'string'
>> dir([num2str(d) '\*.png'])
'string\*.png' not found.
I even tried placing a file named 'string50x.png' in the folder to test this and ended up with the same command output.
I AM trying to find out how to do what you said it did though, so if you've found out how to do that, would you mind replying here?
Walter Roberson
Walter Roberson 2020 年 4 月 14 日
for the case where d = 'string' it searches for files in the current directory that match the file name 'string*.png'
No, it does not. Not that code. If you wanted that to happen, you would need to use '*.png' instead of '\*.png'
Shanuka Jayasinghe
Shanuka Jayasinghe 2020 年 4 月 14 日
Thanks for the reply!
I had also posted a question on reddit, and a user pointed out that i could use the strcat command.
I found that example to work for my specific case, but maybe this will help someone else as well.

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

カテゴリ

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

タグ

質問済み:

2018 年 6 月 29 日

コメント済み:

2020 年 4 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by