Effacer les filtres
Effacer les filtres

How to read a matrix from an ASCII file?

6 vues (au cours des 30 derniers jours)
Julius
Julius le 11 Juin 2012
I have an ASCII file cuboid.mfd. It's content looks as follows:
Version : Marc Mentat 2010.1.0 (32bit)
=beg= 1 (magic)
1234
=end=
=beg= 2 (entities)
84
=end=
=beg= 3 (description)
=end=
=beg= 102 (nodes)
1 2.000000000000e+00 0.000000000000e+00 1.000000000000e+00
0 0
2 2.000000000000e+00 0.000000000000e+00 0.000000000000e+00
0 0
3 1.000000000000e+00 0.000000000000e+00 0.000000000000e+00
0 0
=end=
=beg= 205 (elements)
1 8 0 8
1 2 3 4
13 17 21 25
0 0 0 0
0 0 0 0
=end=
I would like to use the 6x4 matrix (nodes) and the 5x4 matrix (elements) for further calculations. The number of rows and columns of both of the matrices may vary but the structure of the file is always the same. I haven't found any appropriate command to import them. There should be an easy way how to do it.

Réponses (1)

Walter Roberson
Walter Roberson le 11 Juin 2012
None of the built-in data importing commands can handle this, and there is no easy way to do it. You will need to use low-level I/O operations such as fopen(), fgetl(), fscanf(), fclose()
  3 commentaires
Walter Roberson
Walter Roberson le 11 Juin 2012
Nothing works? You are not able to fopen() the file and fgetl() a line at a time and display the line ?
Julius
Julius le 13 Juin 2012
so far, nothing works.....sure I'm able to open the file and display the lines but working with text is something new to me so it took me 2 days to write this code:
fid = fopen('cuboid.mfd','r');
Headlines=textscan(fid,'%s',11,'delimiter','\n');
tline=fgetl(fid);
ix = 1;
while (~feof(fid))
Array{ix}=tline;
tline=fgetl(fid);
ix=ix + 1;
end
fclose(fid);
Now I have only those two matrices separated by '=end=' and don't know how to continue. I tried to convert the lines into numbers to be able to work with ..but it didn't work either

Connectez-vous pour commenter.

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by