problem using textscan: doesnt actually scan anything.

조회 수: 3 (최근 30일)
lab.ag.na2013
lab.ag.na2013 2013년 9월 10일
hi. I am trying to write a program that reads stuff from a text file. as a simple example, i created a .txt file by the name "niv" that has a row:
1 2 3 4
and want to read it into an array. i tried this:
fopen('C:\Users\Lab\Desktop\niv.txt')
num=textscan('niv.txt','%d')
but afterwards, num is empty.... please help !
thanks .

채택된 답변

Friedrich
Friedrich 2013년 9월 10일
편집: Friedrich 2013년 9월 10일
Hi,
try
fid = fopen('C:\Users\Lab\Desktop\niv.txt')
num=textscan(fid,'%d')
fclose(fid)
  댓글 수: 2
Simon
Simon 2013년 9월 10일
Be aware that "num" is a cell array afterwards ...
lab.ag.na2013
lab.ag.na2013 2013년 9월 11일
great, thanks a lot !! :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 9월 10일
You are providing a string 'niv.txt' as the first argument to textscan(). When you provide a string there instead of a file identifier number, it is the content of the string that is scanned rather than the content of the file.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by