

OutageTime OutageDuration Loss Customers Region Cause To remove RestorationTime, use the removevars function. However, in R2018a there is also a function to remove table variables. You can easily remove variables using dot notation and an empty array. OutageTime OutageDuration Loss Customers RestorationTime Region Cause T = addvars(T,OutageDuration, 'After', 'OutageTime') Add OutageDuration so that it is after OutageTime. In R2018a, you can use the addvars function. However, you might want to add it at another location in T. It is easy to add OutageDuration to the end of a table using dot notation. OutageDuration = T.RestorationTime - T.OutageTime Specify the format to display the duration in days. For example, let's calculate the duration of the power outages in T.

It is also likely that you want to add data to your table. OutageTime Loss Customers RestorationTime Region Cause T = movevars(T, 'Region', 'Before', 'Cause') Move the Region variable so it is before Cause. Using movevars, you only have to specify the variables of interest. Starting in R2018a, you can use the movevars function instead. When your table has many variables, it is awkward to move variables using indexing. While more compact, this syntax is less readable. But if you use indexing and want to keep all the variables, then you must specify them all in order, as shown in this syntax. One way to move table variables is by indexing. For example, in T you might want to move Region and Cause so that they are together. (If you do not specify the number of rows, then head and tail return eight rows.) Move, Add, and Delete Table VariablesĪfter examining your table, you might find that you want to organize your table by moving related variables next to each other. Similarly, tail returns the bottom rows of a table. Here's the call to return the first three rows using the head function. Happily, in R2016b we added the head function to return the top rows of a table.
FIND A VALUE ON A PLOT MATLAB 2012 CODE
And occasionally, I still catch myself starting with code like T(3,:), which accesses only one row. I have a confession to make: I have written many table examples, using that syntax. Region OutageTime Loss Customers RestorationTime Cause For example, this syntax returns the first three rows of T. You can use indexing to access a subset of rows (and/or a subset of variables, for that matter). One typical way to examine the data in a large table is to display the first few rows of the table. The call to readtable returns a table, T, with six variables and 1468 rows, so I will suppress the output using a semicolon. The file outages.csv contains simulated data for electric power outages over a period of 12 years in the United States. To begin, I will use the readtable function to read data from a sample file that ships with MATLAB. As of R2018b, MATLAB boasts many new functions to help you make more effective use of tables and timetables.

Also, they offer new ways to make plots or charts directly from tables, without the intermediate step of peeling out variables. These functions add convenient ways to display and arrange tabular data. But over the course of several releases, the table and graphics development teams have added many new functions for tables and timetables. And in R2016b, MATLAB introduced the timetable data type, which is a table that has timestamped rows.įrom the beginning, these data types offered advantages over cell arrays and structures. In R2013b, MATLAB® introduced the table data type, as a convenient container for column-oriented data. Other Functions to Rearrange or Join Tables.
