Main Content

vartype

通过变量类型的下标到表或时间表

Description

example

S = vartype(type)creates a subscript to select table variables of a specified type. Thetype输入argument is a character vector that specifies any type that is accepted by theisafunction, such as'数字','float','integer', or'string'. It also can be'cellstr'to select variables that contain cell arrays of character vectors.

例如,S = vartype('numeric'); T2 = T1(:,S)returnsT2as a table that contains only the numeric variables from the tableT1.

Examples

collapse all

Create a table that contains numeric and string variables. Then subscript into the table to get only its numeric variables.

LastName = string({'Smith';'Johnson';'Williams';'Jones';'Brown'}); Age = [38;43;38;40;49]; Height = [71;69;64;67;64]; Weight = [176;163;131;133;119]; BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80]; T = table(LastName,Age,Height,Weight,BloodPressure)
T=5×5 tableLastName Age Height Weight BloodPressure __________ ___ ______ ______ _____________ "Smith" 38 71 176 124 93 "Johnson" 43 69 163 109 77 "Williams" 38 64 131 125 83 "Jones" 40 67 133 117 75 "Brown" 49 64 119 122 80

创建下标vartype功能。Subscript into the second dimension ofTto return a table that contains only the numeric variables.

S = vartype('数字');t2 = t(:,s)
T2=5×4 tableAge Height Weight BloodPressure ___ ______ ______ _____________ 38 71 176 124 93 43 69 163 109 77 38 64 131 125 83 40 67 133 117 75 49 64 119 122 80

You can create a subscript for any type that theisafunction accepts. Select the string variable fromT.

S = vartype('string');T3 = T(:,S)
T3=5×1 tableLastName __________“史密斯”“约翰逊”“威廉姆斯”“琼斯”“棕色”

Create a timetable that contains numeric, string, and categorical variables. Then subscript into the table to get only its numeric variables.

date = datetime({'12/18/2015';'12/19/2015';'12/20/2015'}); Temp = [45;33;36]; Pressure = [30.1;29.3;29.7]; Location = string({'Boston';'Boston';'Worcester'}); SensorType = categorical({'S1';'X7';'S1'}); TT = timetable(Date,Temp,Pressure,Location,SensorType)
TT=3×4 timetable日期临时压力位置Sensortype ___________ _____________________ __________ 18-dec-2015 45 30.1“波士顿”S1 19-DEC-2015 33 29.3“波士顿”X7 20-DEC-2015 39.7“伍斯特”S1

创建下标vartype功能。Subscript into the second dimension ofTTto return a timetable that contains only the numeric variables.TT2also has the row times fromTT因为时间识别行。行时间的向量是时间表的属性,而不是其变量之一。

S = vartype('数字');TT2 = TT(:,S)
TT2=3×2 timetableDate Temp Pressure ___________ ____ ________ 18-Dec-2015 45 30.1 19-Dec-2015 33 29.3 20-Dec-2015 36 29.7

Input Arguments

collapse all

Type of variables to select from a table or a timetable, specified as a character vector or string scalar.typecan be any type or category that is accepted by theisa功能。它也可以'cellstr'.

Introduced in R2016b