Structure array and file operations
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephen23
2015-4-27
编辑:Stephen23
2015-4-29
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!