How to edit an entire column of a text file using MATLAB?

7 ビュー (過去 30 日間)
Salman Zafar
Salman Zafar 2020 年 12 月 12 日
回答済み: Priyanka Rai 2021 年 1 月 4 日
Hi,
I have text file consist of a node and element connectivity data, with a specific phyiscal property value assigned to each element. I need to change these physical values for every element.
I have attached a sample text file. Precisely, I need to change the values of 'Kxx' and 'Kyy' column.
Is there any way to do this?
  6 件のコメント
Salman Zafar
Salman Zafar 2020 年 12 月 13 日
Actually I need to perform flow analysis on 100 different values of Kxx and Kyy between 1e-11 and 1e-10. So I was thinking to somehow use for loop for this. But I dont know how to do it on data available in text file format.
Mathieu NOE
Mathieu NOE 2020 年 12 月 14 日
sorry, I don't follow
I thought you wanted to change values (in 100 files ? ) , but now you mention I need to perform flow analysis on 100 different values of Kxx and Kyy between 1e-11 and 1e-10
it's not really the same , or ? analysis vs. replacement ??

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

回答 (1 件)

Priyanka Rai
Priyanka Rai 2021 年 1 月 4 日
It is easier to edit files by code. So, if it is possible to hold a file in memory, you can load it to a MATLAB variable, make the required edits, and write back out.
You can read the entire text file using fileread/ readlines and read the parameters separately using readtable. You can then modify the values in the table and write back out.
Text files are sequential, so processing columns basically is easier in memory.
You can also check this readfile function from the FEX (also works pre- MATLAB R2020b).

カテゴリ

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