setvartype
変数のデータ型の設定
説明
例
複数の変数のデータ型の設定
detectImportOptions
を使用してインポート オプションを作成して、複数の変数のデータ型を設定し、readtable
を使用してデータを読み取ります。
オプション オブジェクトを作成します。
opts = detectImportOptions('patients.xls');
変数の現在の (検出された) データ型を調べます。
disp([opts.VariableNames' opts.VariableTypes'])
{'LastName' } {'char' } {'Gender' } {'char' } {'Age' } {'double' } {'Location' } {'char' } {'Height' } {'double' } {'Weight' } {'double' } {'Smoker' } {'logical'} {'Systolic' } {'double' } {'Diastolic' } {'double' } {'SelfAssessedHealthStatus'} {'char' }
インポートのニーズに合わせて、複数の変数のデータ型を変更します。
opts = setvartype(opts,{'LastName','Gender','Location',... 'Smoker','SelfAssessedHealthStatus'},'string'); opts = setvartype(opts,{'Age','Height','Weight',... 'Systolic','Diastolic'},'single');
変数の更新されたデータ型を調べます。
disp([opts.VariableNames' opts.VariableTypes'])
{'LastName' } {'string'} {'Gender' } {'string'} {'Age' } {'single'} {'Location' } {'string'} {'Height' } {'single'} {'Weight' } {'single'} {'Smoker' } {'string'} {'Systolic' } {'single'} {'Diastolic' } {'single'} {'SelfAssessedHealthStatus'} {'string'}
readtable
を使用して更新された型の変数をインポートします。
T = readtable('patients.xls',opts);
入力引数
opts
— ファイル インポート オプション
SpreadsheetImportOptions
| DelimitedTextImportOptions
| FixedWidthImportOptions
ファイル インポート オプション。関数 detectImportOptions
によって作成された SpreadsheetImportOptions
オブジェクト、DelimitedTextImportOptions
オブジェクト、または FixedWidthImportOptions
オブジェクトとして指定します。opts
オブジェクトには、変数プロパティ、データの位置プロパティ、置換ルールなど、データのインポート プロセスを制御するプロパティが含まれます。
selection
— 選択した変数
文字ベクトル | string スカラー | 文字ベクトルの cell 配列 | string 配列 | インデックスの配列 | logical 配列
選択した変数。文字ベクトル、string スカラー、文字ベクトルの cell 配列、string 配列、数値インデックスの配列、または logical 配列として指定します。
変数名 (またはインデックス) は、opts
オブジェクトの VariableNames
プロパティに含まれる名前のサブセットでなければなりません。
例: 'Height'
例: {'Height','LastName'}
例: [5 9]
データ型: char
| string
| cell
| uint64
| logical
type
— 変数のデータ型
文字ベクトル | string スカラー | 文字ベクトルの cell 配列 | string 配列
変数のデータ型。有効なデータ型名を含む文字ベクトル、string スカラー、文字ベクトルの cell 配列、または string 配列として指定します。type
引数は、変数のインポート時に使用するデータ型を指定します。次にリストされているデータ型のいずれかを使用して変数をインポートします。
データ | MATLAB® データ型 |
---|---|
テキスト | |
数値 | 未定義の浮動小数点数
同じ変換プロセスが次のすべての整数データ型に適用されます。 |
論理値 |
|
日付と時刻 |
|
duration |
|
categorical |
|
例: opts = setvartype(opts,'Height','double')
は、変数 Height
のデータ型を double
に変更します。
例: opts = setvartype(opts,{'Weight','LastName'},{'single','string'})
は、変数 Weight
のデータ型を single
に、変数 LastName
のデータ型を string
に変更します。
データ型: char
| string
| cell
バージョン履歴
R2016b で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)