MATLAB: Reading and processing text file

text file reading

Hi,
This probably a simple question for the expert but I am swamped by the too many options. I have a text file (a sample is attached here). The file starts with header where the first line is named as structure and this line is followed by few more text lines and then three columns header and the data. After this data, another line (named as structure) starts and the same continues for couple of more structures. I want to read this file and write it as excel file where each structure start firsts and read data and then the next structure starts in parallel with first one. I have shown it in the excell file attached here. Since there are so many data and couple of structures it would be great if I can write a code. I vastly appreciate any help. I already tried with textscan but could not get it working.

Best Answer

While it's certainly possible to read it the file in matlab and write it to excel the way you want, if it's the only thing you do I don't see the point.
Just open the text file in excel and the importer will do exactly what you want.
Now, if you do insist on doing it matlab:
excel = actxserver('Excel.Application');
wb = excel.Workbooks.OpenText('test_rafiq.txt'); Just call excel text importer with default values
wb.SaveAs('test_rafiq.xlsx');
wb.Close;
excel.Quit;
delete(excel);