フィルターのクリア

Using textscan() to get data from a TXT file, but all cells are NaN

6 ビュー (過去 30 日間)
亦实 胥
亦实 胥 2021 年 11 月 16 日
コメント済み: 亦实 胥 2021 年 11 月 17 日
Now i'm using textscan() to get data from a txt file.
The data in txt file just like "1,2,3,4
2,4,5,7"
[filename, pathname] = uigetfile( ...
{'*.txt'}, ...
'Pick a file');
fid = fopen([pathname filename],'r');
V = textscan(fid,'%0.f %0.f %0.f %0.f','Delimiter',',')
fclose(fid);
I want to get a data array V
but there are something wrong, the cells are [NaN]
I dont konw why.
Please tell me how to debug
v =
1*7 cell array
{[NaN]} {[NaN]} {[NaN]} {[NaN]}

採用された回答

Chunru
Chunru 2021 年 11 月 16 日
Your format specifier is not correct.
s=["1,2,3,4"
"2,4,5,7"]
s = 2×1 string array
"1,2,3,4" "2,4,5,7"
V = textscan(s(1),'%f %f %f %f','Delimiter',',')
V = 1×4 cell array
{[1]} {[2]} {[3]} {[4]}
V = textscan(s(1),'%0.f %0.f %0.f %0.f','Delimiter',',')
V = 1×4 cell array
{[NaN]} {[NaN]} {[NaN]} {[NaN]}

その他の回答 (0 件)

カテゴリ

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