Read data from textfile
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
TastyPastry
am 2 Nov. 2015
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.
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!