# Matlab column extraction sematics

2 visualizzazioni (ultimi 30 giorni)
Max Yaffe il 25 Mar 2023
Modificato: Walter Roberson il 27 Mar 2023
I'm learning Matlab and taking the Signal Processing Onramp. Can someone explain the difference between the two statements below
form1 = quakes(:,"WANC")
form2 = quakes.WANC
form1 returns a timetable with 2 columns, time and the WANC data column.
form 2 returns a column vector with just the WANC data.
quakes is a timetable with several columns, one of which is named WANC.
I should also note that the 2nd statement of these two fail which sort-of makes sense since quakes.WANC doesn't contain time info.
bandpass(quakes(:,"WANC"), [2 10])
bandpass(quakes.WANC, [2 10])
I expected form1 to be the same as form2. Is there some guide to datatypes and operations on them in Matlab that would cover this?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Stephen23 il 25 Mar 2023
Modificato: Stephen23 il 25 Mar 2023
" Is there some guide to datatypes and operations on them in Matlab that would cover this?"
Note that you can easily find all of the documentation on tables: https://www.mathworks.com/help/matlab/tables.html
These documentation pages are also easy to lcoate using your favorite internet search engine.
As the documentation explains, there are actually three types of indexing into tables and timetables. For accessing the content of just one column/variable, the following are equivalent:
form3 = quakes{:,"WANC"} % note curly braces, not parentheses
form2 = quakes.WANC
"I expected form1 to be the same as form2."
In MATLAB the meaning of indexing with parentheses is very very simple: you will always get a sub-array of the same type as the array that you are indexing into. For example, if you index into a cell array using parentheses then you will get another cell array. If you index into a character array with parentheses you will get another character array. If you index into a timetable with parentheses then you will get another timetable (and not its content, which is returned by using curly-braces or dot indexing). So if you know QUAKES is a timetable, then you already know FORM1 is too:
form1 = quakes(:,"WANC") % parentheses returns same type as QUAKES is
Note that timetable FORM1 actually only has one column/variable, because the times are considered to be something like rownames (and the rownames/times are not a column/variable in the table). Confirming this is left as an exercise for the reader.
##### 5 CommentiMostra 3 commenti meno recentiNascondi 3 commenti meno recenti
Max Yaffe il 27 Mar 2023
Doesn't have a Matrix class? But references to "Matrix" abound, especially on the fundamental-matlab-classes page (thanks, I think that is actually what I'm looking for.) Maybe my confusion is around the term class which, typical of OO dynamic languages (Smalltalk, Python), everything is an object and every object has a class. I'll keep reading. This has been helpful.
Walter Roberson il 27 Mar 2023
Modificato: Walter Roberson il 27 Mar 2023
There are some (many) programming languages in which an item of data type double is considered to be a different class than matrix of double . In some of those languages, any matrix of double is considered to be the same data type as any other matrix of double but in other languages, each different size of matrix is considered to be a different class, or a different class is used when fixing all but one dimension of the matrix (for example 5 by 3 by 9 matrix of double might be a compatible data type with 5 by 3 by 11 matrix of double
But in MATLAB, each object has a size attribute that is different from its class. A 5 by 3 by 9 matrix of double in MATLAB is the same class as an 1 x 99 matrix of double. There is a size() operation that is supported for every object.
There are some classes that deliberately write size restrictions into their semantics. For example the "function handle" class deliberately disallows constructing non-scalar function-handle objects -- you cannot for example do f(2) = @sin . And some classes might interpret size information a bit differently, such as indicating the number of inputs and outputs for a control system. But a tf control system with 1 input and 2 outputs is the same class as a control system with 3 inputs and 1 output.
The class for a numeric array is most often double but other numeric data types such as unsigned 16 bit integer also exist, and are different class than double .
MATLAB does not allow you to directly say that the permitted functions (methods) for [say] 3 x 3 arrays of double is diferent than the permitted functions for [say] 4 x 4 arrays of double. You can define different classes that happen to only support 3 x 3 arrays as properties and define functions for that class, but asking about the class of such an object would return the name of the class, not double
Numeric arrays and character arrays and logical arrays are fundamental data types in which every element of the arrays are of the same data types. There are also composite data types such as struct and cell arrays and table objects, in which different portions of the composite data might be different data types. string arrays require that the contents are all the same data type, but they can also be treated as a composite data type, similar to a cell array of character vectors together with some extra methods.

Accedi per commentare.

### Categorie

Scopri di più su Tables in Help Center e File Exchange

R2021b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by