読み込めるファイルと読み込めないファイルの違い
Ältere Kommentare anzeigen
以下のコードを用いて添付のファイルを読み込むとY001.txtは読み込めるのですが,Y002.txtでは次の太字で示したエラーメッセージが出ます.ファイルは同じ形式なので改善方法が思いつきません.どのようにすれば改善できるでしょうか?
Y002.txt
次を使用中のエラー: {}
データ型が double と cell であるため、table 変数 'Depth[m]' および 'Density[Mg/m^3]' を連結できません。
エラー: table2array (行 37)
a = t{:,:};
エラー: ppp (行 32)
D = table2array(t);
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
%対象のファイル範囲
start_index = 1;
end_index = 2;
%ファイルのベースネーム
base_name = 'Y';
%ファイルの拡張子
file_ext = '.txt';
for i = start_index:end_index
%ファイル名を生成
Fname = [base_name, num2str(i,'%03d'),file_ext];
%ファイルの内容を読み込む
load = fileread(Fname);
%テキストの内容を読み込むか読み込まないかの判別
if ~contains(load, 'Sorry, We have no soil condition data.')
%ファイルの読み込み処理をここに追加
disp(Fname);
%データの読み込み
%Delimiterが半角スペースであることを明示的に指定
%半角スペースの連続は1つのDelimiterとして扱う
t = readtable(Fname,"NumHeaderLines", 3, "ReadVariableNames", false, "Delimiter", " ", "ConsecutiveDelimitersRule", "join");
%不要な部分を削除
t (:,[1 7:end]) = [];
%ヘッダーの名前を決定
t.Properties.VariableNames = {'Depth[m]', 'N-Value', 'P-Velocity[m/s]', 'S-Velocity[m/s]', 'Density[Mg/m^3]'};
t.("Depth[m]") = str2double(erase(t.("Depth[m]"),'m'));
D = table2array(t);
%データの表示
disp(t)
data_cell_array{i} = D;
else
disp(['Skipped file: ' Fname]);
end
end
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu cell 配列 finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!