필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Importing a text with header

조회 수: 1 (최근 30일)
Sermed
Sermed 2012년 3월 28일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi All I have a text file that i want to import to Matlab. This file is as shown: * Item one % 1 text text tex * Item two 1 2 2 3 4 5 3 2 * Item three % 2 text text text * Item four 12 12 45 7 8 6
how can i import the two vectors? Thanks

답변 (2개)

Richard
Richard 2012년 3월 28일
Its hard to say with the example you provided but I think you should be looking at using textscan
  댓글 수: 2
Sermed
Sermed 2012년 3월 29일
Thanks lestyn
Yeah the output of my message was not clear.
The idea is: I have four lines in my text file, the first and the third are commented (begin with %) and the second and the fourth lines are vectors of integers.
How can i extract the two vectors?
Ken Atwell
Ken Atwell 2012년 4월 3일
Sermed, textscan is likely the right chose. Read the doc page lestyn indicated, especially the CommentStyle option -- you should be able to ignore lines that begin with a '%'.

Richard
Richard 2012년 3월 29일
by saying lines, do you mean row or column vectors? Either way, try to use dlmread first:
M = dlmread(filename)
so your filename will be the path where the text file is located e.g.
C:\My Documents\textFile.txt
where textFile is the specific name of your text file. If this doesn't work let me know and we can try and think of another method.
  댓글 수: 2
Sermed
Sermed 2012년 4월 3일
Thanks again lestyn
I've tried with dlmread function but it returnes an error statment if the text file included other than integers.
I tried with textscan as well but i managed to read only the first vector.!
Can i send you the text and m.file?
thanks in advance
Sermed
Richard
Richard 2012년 4월 3일
Sure.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by