Structure array and file operations

3 ビュー (過去 30 日間)
Steve
Steve 2015 年 4 月 27 日
編集済み: Stephen23 2015 年 4 月 29 日
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

採用された回答

Stephen23
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);
  1 件のコメント
Steve
Steve 2015 年 4 月 29 日
Thankyou! Greatly appreciated!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by