Structure array and file operations
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Steve
el 27 de Abr. de 2015
Hello,
I am reasonably new to MATLAB and am stuck on a question regarding structure arrays. So basically it wants me to get MATLAB to read data from a .txt file, and return values with a title, these values are number of triangles (1st value), height and width (alternating values, 2nd is height, 3rd width etc), along with this it also needs to calculate the area of the triangle. Now, this data is quite randomized but apparently Matlab will be able to read it. I've really only got the basics but I am guessing I will need to use fscanf and readf? The struct function is simple enough i just dont know how to mix the three. I have uploaded the question along with a photo of some of the data.


Thanks, Regards Steve
0 comentarios
Respuesta aceptada
Stephen23
el 27 de Abr. de 2015
Editada: Stephen23
el 29 de Abr. de 2015
You can find a list of functions that can read textfiles here:
I would recommend that you use textscan, which can also convert the string data to the numeric values. However that sample file is a bit mixed-up, and does not have a simple layout. You might need to read the first part of the file line-by-line using some low level functions, and then the rest of the file using textscan. Here is a list of the low-level file-reading functions:
you might find fgetl very useful for this purpose!
Also note that if you keep a file open then (most of) these functions continue to read the file from the point where the last function finished, so you can do things like this:
fid = fopen(filename,'rt');
A = fgetl(fid);
B = fgetl(fid);
C = textscan(fid,...);
...
fclose(fid);
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!