How to import data from .txt file?

25 ビュー (過去 30 日間)
Max-Henri Froger
Max-Henri Froger 2020 年 8 月 11 日
回答済み: Jeremy Hughes 2020 年 8 月 11 日
Hello everyone,
I am doing an application on App Designer and I need to extract data from a simple txt file architecture (as shown below). After extracted the data, I need to save them on a matlab file but I don't find the way to do that.
I code this but it's not working
[filename,pathname]=uigetfile({'*.fl.txt' 'Torque file (*.fl.txt)'},'Select a torque curve');
if filename ~= 0
extracted=textscan([filename,pathname],'%f %f')
CDC_N=extracted(:,1)
CDC_Torque=extracted(:,2)
save(CDC.mat,'CDC_N','CDC_Torque');
end
if anyone could help me, I'd be grateful.
thanks

採用された回答

KSSV
KSSV 2020 年 8 月 11 日
data = importdata(mytextfile) ;

その他の回答 (1 件)

Jeremy Hughes
Jeremy Hughes 2020 年 8 月 11 日
The textscan function expects a fileID, not a file name. you need to use fopen.
[filename,pathname]=uigetfile({'*.fl.txt' 'Torque file (*.fl.txt)'},'Select a torque curve');
if filename ~= 0
fid = fopen(fullfile(pathname,filename));
extracted=textscan(fid,'%f %f');
fclose(fid);
CDC_N=extracted(:,1)
CDC_Torque=extracted(:,2)
save(CDC.mat,'CDC_N','CDC_Torque');
end

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by