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!