what are tables and how are they used in matlab video -凯发k8网页登录
table arrays store column-oriented or tabular data, such as columns from a text file or spreadsheet. tables store each piece of column-oriented data in a variable which may contain different types of data. learn how to take advantage of matlab tools and functionalities to perform everything from high-level analysis to complex functions on external table data such as excel spreadsheets or tabular data.
welcome to using tables in matlab! in this video, we’ll define what a table is in matlab, how to import external table data into matlab from programs like excel, and how to perform basic functions on the table using matlab.
table arrays store column-oriented or tabular data, such as columns from a text file or spreadsheet. tables store each piece of column-oriented data in a variable which may contain different types of data. for instance, tables may contain numerical data, alphanumerical or text strings, or categorical data. in this video, we will focus on working with numerical and alphanumerical data.
tables are often found in formats such as spreadsheets or delimited-value files. you’re probably familiar with tables in programs like excel. you can import, analyze, and extract table data in matlab without having to manually recreate a table from excel. let’s look at an example.
here, we have an excel table with the average summer highs at mathworks locations in north america. you’ll see we have three different data types in the table: text strings, categorical, and numerical. for this video, we will focus on working with alphanumeric and numerical data.
let’s get this table imported into matlab.
to import a table into matlab, click on “import data” in the top toolbar.
navigate to where your table is located, select it, and click open.
you’ll see that matlab is able to determine the table elements. first, you’ll see the name of the table at the top based on the file name. second, you’ll see the table headers; these are called variable names in matlab. you can adjust the row of variable names using the drop-down menu at the top. third, you’ll see the data types. in this example, you’ll see locations represented as text data, time zones represented as categorical data, and temperatures represented as numerical data.
if you want to change any data in the table, you can do so by double-clicking the corresponding cell .
if you want to change the data type of any variable, use the drop-down menu.
once you are satisfied with the data you want to import, click import selection. in matlab, you’ll see the table in the workspace.
at any point, you can make changes to the table, by double-clicking on the table in the workspace to open the variable editor, selecting any of the cells, and making any necessary changes to its value. you’ll notice that as you make any changes, it will display programmatically in the command window.
by right-clicking on aany variable, you can sort the data as if you were in excel, delete data, or export data into a separate table. you can also add metadata to each variable.
to obtain a high-level overview of table data, you can use the summary function to view a quick analysis of the table data by column. for instance, we see there are three mathworks locations in the pacific standard time zone, and the median average temperature in july of the mathworks north america locations is 82 degrees.
you can do more than just analyze data using tables in matlab.
you can use dot-indexing to perform functions on a single variable. for example, if we want to find the mean (average) temperature of the north america locations in august, it can be easily done using the mean function.
let’s assign meanaugtemp to equal the mean of august temperatures. and you’ll see the average temperature in august of the north american locations is 81.5 degrees.
what if you want to focus on a specific variable of the table? you can use curly braces ({}) to extract data from one variable into a single array. for instance, let’s extract the july temperatures for further analysis. we can extract the variable with the following syntax: sampletable{1:5, ‘july’}
you can also concatenate the data further by extracting multiple variables. if we wanted to extract july and august temperatures for further analysis, we would use the following syntax: sampletable{1:5, ‘july’ ‘august’}. this extracts the data into a single array.
if you want to extract specific variables of a table into a new table, you can do so with the following syntax using paranthesis: define the new table name = sampletable(1:5, ‘july’ ‘august’)
you can even add variables to a table using functions. for instance, if we wanted to calculate the mean of each location’s summer temperature, we would have to add each average temperature – june, july, and august – and then divide by three. in matlab, we would use the following syntax: sampletable.meantemp = (sampletable.june sampletable.july sampletable.august)/3. we’ll see that it adds the new variable to the end of the table and performs the calculation.
there are many other functions you can perform on tables variables. the matlab help documentation on tables and variables has lots of information, examples, and live scripts you can download to practice. to access the help documentation, click on the question mark icon in the top right.
in this video, we covered how to define a table and the types of data tables contain, how to perform an analysis of the data, and how to perform basic functions. take advantage of matlab tools and functionalities to perform everything from high-level analysis to complex functions on external table data such as excel spreadsheets or tabular data. if you’re ready to take the next step using tables in matlab, we have more videos on importing excel spreadsheets, performing complex table functions, and using categorical data in tables.
featured product
matlab
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 mathworks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- (español)
- (english)
- (english)
欧洲
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
亚太
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)