フィルターのクリア

Read a text file with a common name

1 回表示 (過去 30 日間)
H-H
H-H 2014 年 10 月 30 日
回答済み: Geoff Hayes 2014 年 10 月 30 日
Hi, I have a program X that generate each time a text file (including some numbers in the file) with a specific name that reflects the current iteration number i.e. "App.in.1", "App.in.2",... . The program X delete the old file (e.g. "App.in.1") after each iteration and creates a new file (e.g. "App.in.2").
I want to have a matlab code that be able to automatically read the current file that include "APP.in." (for example "APP.in.50"), get the iteration number say 50, do some operations, and write back a new file ""APP.out.50". Program X then takes over this text file and deletes it afterwards.
How to write such small matlab code that can read the current file name at time n "App.in.n", and write back a file with name "App.out.n"
Thank you.

回答 (1 件)

Geoff Hayes
Geoff Hayes 2014 年 10 月 30 日
If all file names follow this format (iteration number is preceded by App.in.), then just do something like
inPrefix = 'App.in.';
outPrefix = 'App.out.';
currInFilename = 'App.in.50';
currIteration = currInFilename(length(inPrefix)+1:end);
currOutFileName = [outPrefix currIteration];
We rely on the fact that all current iteration files are prefixed with App.in. so we just remove all of this from currInFilename by considering the substring from the index that follows this prefix (so length(inPrefix)+1) to the end of the string in order to extract the iteration number. We then concatenate that string with the output prefix to get
currOutFileName =
App.out.50

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by