テキストファイルの読み込みについて
95 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
文字列と数値を含むテキスト(.txt)をMATLABで読み込ませようとしています。
※テキストは以下のようにカンマ[,]で区切られています。
TEST.txt
TEST1,TEST2,TEST3,
RES,
100,80,90,
20,20,10,
次がMATLABのコードです
SET = textscan(fileID,'%s','delimiter', '');
これを実行すると変数はcell配列で
SET(1,1)にTEST1,TEST2,TEST3,
SET(2,1)にRES,
SET(3,1)に100,80,90,
SET(4,1)に20,20,10,
この様になります。
ここで以下のように出力できないか悩んでいます。
SET(1,1)TEST1 SET(1,2)TEST2 SET(1,3)TEST3
SET(2,1)RES
SET(3,1)100 SET(3,2)80 ・・・以降略
カンマ区切りでセルに入れることは可能でしょうか?
宜しくお願いします。
MATLABは2013bを使用しています。
実際のデータは10000行以上あります。
0 commentaires
Réponse acceptée
madhan ravi
le 29 Mar 2019
Modifié(e) : madhan ravi
le 29 Mar 2019
fileID = fopen('TEST.txt');
SET = textscan(fileID,'%s','delimiter','\n');
fclose(fileID);
S = SET{:};
SET = cellfun(@(x)regexp(x,'\w*(?=\,)','match'),S,'un',0);
% SET{:}
% celldisp(SET)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Analytics Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!