Main Content

removevars

table または timetable からの変数の削除

説明

T2 = removevars(T1,vars) は、vars で指定された table 変数を削除し、残りの変数を T2 にコピーします。変数は名前や位置で指定するか、論理インデックスを使用して指定することができます。

たとえば、table 変数 var3 を削除するには、T2 = removevars(T1,'var3') を使用します。

すべて折りたたむ

table を作成し、変数を 1 つずつ削除します。変数は名前または table 内の位置によって指定できます。

データをスプレッドシートから table に読み取ります。最初の 3 行を表示します。

T1 = readtable('outages.csv');
head(T1,3)
       Region             OutageTime          Loss     Customers       RestorationTime            Cause      
    _____________    ____________________    ______    __________    ____________________    ________________

    {'SouthWest'}    01-Feb-2002 12:18:00    458.98    1.8202e+06    07-Feb-2002 16:50:00    {'winter storm'}
    {'SouthEast'}    23-Jan-2003 00:49:00    530.14    2.1204e+05                     NaT    {'winter storm'}
    {'SouthEast'}    07-Feb-2003 21:15:00     289.4    1.4294e+05    17-Feb-2003 08:14:00    {'winter storm'}

Region という名前の変数を削除します。

T2 = removevars(T1,'Region');
head(T2,3)
         OutageTime          Loss     Customers       RestorationTime            Cause      
    ____________________    ______    __________    ____________________    ________________

    01-Feb-2002 12:18:00    458.98    1.8202e+06    07-Feb-2002 16:50:00    {'winter storm'}
    23-Jan-2003 00:49:00    530.14    2.1204e+05                     NaT    {'winter storm'}
    07-Feb-2003 21:15:00     289.4    1.4294e+05    17-Feb-2003 08:14:00    {'winter storm'}

T2 から 4 番目の変数を削除します。

T3 = removevars(T2,4);
head(T3,3)
         OutageTime          Loss     Customers          Cause      
    ____________________    ______    __________    ________________

    01-Feb-2002 12:18:00    458.98    1.8202e+06    {'winter storm'}
    23-Jan-2003 00:49:00    530.14    2.1204e+05    {'winter storm'}
    07-Feb-2003 21:15:00     289.4    1.4294e+05    {'winter storm'}

関数 removevars を使用して複数の table 変数を削除します。変数は名前または位置によって指定できます。

データをスプレッドシートから table に読み取ります。

T1 = readtable('outages.csv');
head(T1,3)
       Region             OutageTime          Loss     Customers       RestorationTime            Cause      
    _____________    ____________________    ______    __________    ____________________    ________________

    {'SouthWest'}    01-Feb-2002 12:18:00    458.98    1.8202e+06    07-Feb-2002 16:50:00    {'winter storm'}
    {'SouthEast'}    23-Jan-2003 00:49:00    530.14    2.1204e+05                     NaT    {'winter storm'}
    {'SouthEast'}    07-Feb-2003 21:15:00     289.4    1.4294e+05    17-Feb-2003 08:14:00    {'winter storm'}

Loss および Customers という名前の変数を削除します。文字ベクトルの cell 配列を使用して名前を指定します。

T2 = removevars(T1,{'Loss','Customers'});
head(T2,3)
       Region             OutageTime           RestorationTime            Cause      
    _____________    ____________________    ____________________    ________________

    {'SouthWest'}    01-Feb-2002 12:18:00    07-Feb-2002 16:50:00    {'winter storm'}
    {'SouthEast'}    23-Jan-2003 00:49:00                     NaT    {'winter storm'}
    {'SouthEast'}    07-Feb-2003 21:15:00    17-Feb-2003 08:14:00    {'winter storm'}

1 番目と 4 番目の変数を、T2 内の位置を示す数値配列を使用して削除します。

T3 = removevars(T2,[1 4]);
head(T3,3)
         OutageTime           RestorationTime   
    ____________________    ____________________

    01-Feb-2002 12:18:00    07-Feb-2002 16:50:00
    23-Jan-2003 00:49:00                     NaT
    07-Feb-2003 21:15:00    17-Feb-2003 08:14:00

入力引数

すべて折りたたむ

入力 table。table または timetable として指定します。

入力 table の変数。string 配列、文字ベクトル、文字ベクトルの cell 配列、pattern スカラー、数値配列、または logical 配列として指定します。

例: T2 = removevars(T1,2) は 2 番目の table 変数を削除します。

例: T2 = removevars(T1,'Date')Date という名前の table 変数を削除します。

例: T2 = removevars(T1,{'Latitude','Longitude','Elevation'})LatitudeLongitudeElevation という名前の table 変数を削除します。

拡張機能

バージョン履歴

R2018a で導入