I am trying to load an ASCII file that I downloaded from CST. But the usual load tricks that I do don't seem to work and I cannot seem to find the correct method to load the file. The ASCII text file has multiple columns and a the headers are seperated from the rest of the column with one row of --------- signs. This makes it harder to put the columns into variables. Is there any advice to fix this issue?
Thank you,
Nandakumar

3 件のコメント

jonas
jonas 2020 年 7 月 25 日
Please upload the file or a smaller sample file.
KSSV
KSSV 2020 年 7 月 25 日
Read about textscan. This might be useful.
Nandakumar Unnikrishnan
Nandakumar Unnikrishnan 2020 年 7 月 25 日
I am attaching Trial 1.zip (since the txt file was too big). I tried textscan too, but that did not seem to work correctly. I could have used it wrong, but since I've not used it before I don't know for sure.

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

 採用された回答

jonas
jonas 2020 年 7 月 25 日
編集済み: jonas 2020 年 7 月 26 日

1 投票

Based on the sample given in the comments
A = readmatrix('Trial 1.txt')
or better yet,
opts = detectImportOptions('Trial 1.txt','VariableNamesLine',1);
T = readtable('Trial 1.txt',opts);
for older versions you can use textscan
fid = fopen('Trial 1.txt')
out = textscan(fid,repmat('%f',1,10),'headerlines',2,'collectoutput',1)
fclose(fid)

5 件のコメント

Nandakumar Unnikrishnan
Nandakumar Unnikrishnan 2020 年 7 月 25 日
Neither of those seems to work:
This happens when I tried both. I only tried the first line for opts since if that didn't work the second line would be even worse. Any other ideas?
Thank you for trying to help though, it is much appreciated.
Walter Roberson
Walter Roberson 2020 年 7 月 25 日
Either your installation of MATLAB is corrupt, or else you forgot to mention that you are using a release before R2019b (in which case we need to know which release you are using.)
Nandakumar Unnikrishnan
Nandakumar Unnikrishnan 2020 年 7 月 25 日
I am using the R2017a version. I did not realize that the versions would matter this much
jonas
jonas 2020 年 7 月 26 日
I've updated the answer to include textscan()
Nandakumar Unnikrishnan
Nandakumar Unnikrishnan 2020 年 7 月 26 日
Thank you. This seems to work now

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Import and Export についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by