how to read a .txt file and change the value of a parameter in that file

4 ビュー (過去 30 日間)
Ashehad Ali
Ashehad Ali 2015 年 4 月 26 日
コメント済み: Geoff Hayes 2015 年 4 月 27 日
Hi there,
I'm relatively new to Matlab. I'd like to read or maybe scan the attached paramin.txt file in Matlab and change the value of a parameter in that file and thus the file would contain the updated value of that parameter.
I've been able to do that quite easily in R using a "replacePAR" function as follows: For example, to change the current value of SLAA to 6, I'd just use the following syntax in R: replacePAR("paramin.txt",parname="SLAA", newval=6.0)
I'm wondering if there's an equivalent function in Matlab. Find attached the paramin.txt file that contains texts and values.
I'd appreciate your assistance.
Thanks, Ashehad

採用された回答

Geoff Hayes
Geoff Hayes 2015 年 4 月 26 日
Ashehad - the replacePAR function seems to have been written for files of a certain format (MAESTRA/MAESPA input files). Is this the case? If so, you could try to find a similar MATLAB function from the File Exchange (though I couldn't find any submissions for files of this type).
A quick and (not so efficient) example is attached that works for the file that you have attached. It creates a temporary file and updates it with the new parameter value, and then replaces the original file with the new one. Just call it from the Command Window as
replacePAR('paramin.txt','SLAA',6.0)
  2 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 4 月 27 日
Ashehad's answer moved here
Thanks, Geoff - it works! Yes, the replacePAR function had been written for MAESTRA/MAESPA input files.
Geoff Hayes
Geoff Hayes 2015 年 4 月 27 日
Glad it worked, Ashehad!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by