I have a question about a command I would like to use. I have several files with multiple suffixes, for example file_1.txt, file_2.txt, file_3.txt etc.
I would like to read a specific file depending on a value of a variable. For example if my value is equal to 4 I would like to read file file_4.txt. if my value is equal to 5 I would like to read file file_5.txt.
Which command should I use in order to make it?
Coule you please help me?

 採用された回答

Dyuman Joshi
Dyuman Joshi 2022 年 12 月 5 日

0 投票

d=5;
s=sprintf('file_%d.txt',d)
s = 'file_5.txt'
%command for reading the file
fileread(s)

その他の回答 (0 件)

カテゴリ

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

質問済み:

2022 年 12 月 5 日

回答済み:

2022 年 12 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by