同じ形式のファイルを読み込もうとするとエラーが出ます.
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    拳志朗
 el 30 de Nov. de 2023
  
    
    
    
    
    Comentada: 拳志朗
 el 1 de Dic. de 2023
            Fname='AIC010.txt';%データの読み込み
t=readtable(Fname,...
    "NumHeaderLines",3,"ReadVariableNames",false);%ヘッダーの行数
t(:,6:end)=[];%不要な部分(Soil Column)を削除
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'));%深さを数値とする
disp(t)%表示する
次を使用中のエラー:  . 
VariableNames プロパティにはテーブル内の変数ごとに名前を 1 つ指定しなければなりません。
エラー: untitled2 (行 7)
t.Properties.VariableNames={'Depth[m]', 'N-Value', 'P-Velocity[m/s]',...
AIC001で実行した場合は以下のようになります.
Depth[m]    N-Value    P-Velocity[m/s]    S-Velocity[m/s]    Density[Mg/m^3]
    ________    _______    _______________    _______________    _______________
        1          2             360                 78                1.8      
        2         13             360                 78               1.68      
        3         14             360                130               1.72      
        4          4             360                130               1.71      
        5          2            1600                130               1.68      
        6          5            1600                130               1.71      
        7         13            1600                130               1.88      
        8          6            1600                130               1.89      
        9          7            1600                130                1.9      
       10         22            1600                130                1.9      
       11         27            1600                200               1.89      
       12         24            1600                200               1.87      
       13         17            1600                200               1.87      
       14         12            1600                200               1.86      
       15         11            1600                200               1.85      
       16         20            1600                200               1.89      
       17         29            1600                200                1.9      
       18         26            1600                200               1.92      
       19         24            1600                200               1.82      
       20         26            1600                200               1.85    
AIC010の時にエラーが出るのかわかりません.
0 comentarios
Respuesta aceptada
  Akira Agata
    
      
 el 30 de Nov. de 2023
        もしかすると 2 つのファイルの Delimiter の微妙な違いが影響している可能性があります (いずれも単純なタブ区切りではなく、半角スペースの連続で区切っているようです)。試したところ、readtable のオプションをより詳細に指定することで対応できました。
% 対象データ
% AIC010 (AIC001の場合は2番目のURLを使用)
url = "https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1556142/AIC010%20.txt";
% url = "https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1556147/AIC001.txt";
% データ部分を読み込み
t1 = readtable(url,...
  "NumHeaderLines", 3,...
  "ReadVariableNames", false,...
  "Delimiter"," ",...                   % Delimiterが半角スペースであることを明示的に指定
  "ConsecutiveDelimitersRule", "join"); % 半角スペースの連続は1つのDelimiterとして扱う
% 不要な列を削除
t1(:,[1 7:end]) = [];
% ヘッダーの名前を決定
t1.Properties.VariableNames = {'Depth[m]', 'N-Value', 'P-Velocity[m/s]',...
    'S-Velocity[m/s]', 'Density[Mg/m^3]'};
% 深さを数値とする
t1.("Depth[m]") = str2double(erase(t1.("Depth[m]"), 'm'));
% 表示する
disp(t1)
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
