Read data from textfile
1 回表示 (過去 30 日間)
古いコメントを表示
Hi all,
I have this program consisting of many scripts. I have an input.m file where I define and give values to all design parameters. The parameters are assigned as structures and the values as vectors. For example:
% Multi Load Calculations
I.Load=[0.25 0.50 0.75 1];
I.SFOC=[0.1822 0.1751 0.1727 0.1776];
% Single Load
I.lamda=3.5;
I.A_F_stoic=14.4;
I.SMCR=23000;
I want to substitute the Inputs.m file with a txt file (Data.txt) so that I can run my program as executable but still be able to access and modify my inputs.file.
Does anyone know how can I write the above code in a txt file so that Matlab can read it and import the data that I give? I would also like to use comments like in the .m file so that the user understands what parameters' value is being modified.
Thanks a lot in advance
0 件のコメント
回答 (1 件)
TastyPastry
2015 年 11 月 2 日
You could write something like data.txt:
.25 .5 .75 1
.1822 .1751
...etc.
Then use something like textscan() or just parse the data line by line into variables. If you'd like to put comments into the file you can just have Matlab skip over those lines when it's reading in the text lines.
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!