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!