how to load an ASCII file

조회 수: 146 (최근 30일)
Nandakumar Unnikrishnan
Nandakumar Unnikrishnan 2020년 7월 25일
댓글: Nandakumar Unnikrishnan 2020년 7월 26일
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
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일
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
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개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by