Skipping first few lines while loading text file

I have a text file which looks like the one attached. How to skip first five lines and import the rest as a matrix. Thanks in advance for help

 採用された回答

Guillaume
Guillaume 2019 年 10 月 26 日

0 投票

That file is a mess. It looks like the number of spaces around the numbers is significant, which is never a good idea.
Thankfully for you readmatrix seem to import the file correctly. It also detects the number of header lines on its own. All the importing functions (csvread, dlmread, readtable, readmatrix) allows you to specify the number of header lines if you need to. The last two can detect that automatically, so:
data = readmatrix('Full_beam-OAM_plate_l= 1_Intensity.txt')

5 件のコメント

alok pandey
alok pandey 2019 年 10 月 26 日
I am sorry but I tried this option previously but with no success. I have an error saying :
Undefined function or variable 'readmatrix'.
Error in skipheader (line 10)
data = readmatrix('Full_beam-OAM_plate_l= 1_Intensity.txt');
>> readmatrix
Undefined function or variable 'readmatrix'.
Guillaume
Guillaume 2019 年 10 月 26 日
Since you didn't put the version of matlab you are using in the field designed for that purpose (on the right of the web page), I assumed you were using a recent version. If you are using an old version before readmatrix was introduced, then yes you will get that error.
So we dont' waste our time giving you non-applicable answers: which version are you using?
alok pandey
alok pandey 2019 年 10 月 26 日
Yes! My apologies and thanks again. I'm using 2017b.
Guillaume
Guillaume 2019 年 10 月 26 日
Then the easiest is problaby:
data = table2array(readtable('Full_beam-OAM_plate_l= 1_Intensity.txt'))
alok pandey
alok pandey 2019 年 10 月 26 日
Thanks Guillaume. Cheers for your rapid response.

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

その他の回答 (0 件)

製品

リリース

R2017b

質問済み:

2019 年 10 月 26 日

コメント済み:

2019 年 10 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by