I have a text file (lets call it an input file) of this type:
%My kind of input file % Comment 1 % Comment 2
4 %Parameter F
2.745 5.222 4.888 1.234 %Parameter X
273.15 373.15 1 %Temperature Initial/Final/Step
3.5 %Parameter Y
%Matrix A
1.1 1.3 1 1.05
2.0 1.5 3.1 2.1
1.3 1.2 1.5 1.6
1.3 2.2 1.7 1.4
I need to read this file and save the values as variables or even better as part of different arrays. For example by reading I should obtain Array1.F=4;
then Array1.X
should be a vector of 3 real numbers, Array2.Y=3.5
then Array2.A
is a matrix FxF
. There are tons of functions to read from text file but I don't know how to read these kind of different formats. I've used in the past fgetl/fgets
to read lines but it reads as strings, I've used fscanf
but it reads the whole text file as if it is formatted all equally. However I need something to read sequentially with predefined formats. I can easily do this with fortran reading line by line because read has a format statement. What is the equivalent in MATLAB?