problem using textscan: doesnt actually scan anything.

2 ビュー (過去 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 Center および 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