Matlab Structure & Table Quiz

Matlab
0 Passed
0% acceptance

40 comprehensive questions on MATLAB's structure and table data types covering struct fields, nested structures, table creation, row/column access, and table operations — with 16 code examples to master MATLAB's cpp quiz structured data capabilities.

40 Questions
~80 minutes
1

Question 1

What is a structure in MATLAB?

A
Structure is a data type that groups related data using named fields, allowing organization of heterogeneous data with descriptive field names for better code readability
B
Structure is identical to regular arrays
C
Structure stores only numeric data
D
Structures are not supported
2

Question 2

How do you create a structure in MATLAB?

matlab
person.name = 'John';
person.age = 30;
person.city = 'Boston';
A
Use dot notation to assign values to named fields, creating structure with descriptive field names for organized data storage and access
B
Use struct() function only
C
Use parentheses for structure creation
D
Structures cannot be created directly
3

Question 3

How do you access structure fields?

matlab
person.name = 'John';
name_value = person.name;
A
Use dot notation with field name to access structure field values, providing clear and readable data retrieval from structured data
B
Use parentheses for field access
C
Use curly braces for structure access
D
Structure fields cannot be accessed
4

Question 4

What is a nested structure?

matlab
company.employee.name = 'John';
company.employee.age = 30;
A
Nested structure contains other structures as field values, enabling hierarchical data organization and complex relationship representation in single variable
B
Nested structure is a regular structure
C
Nested structures are not supported
D
Nested structure stores only numbers
5

Question 5

How do you create a table in MATLAB?

matlab
names = {'John'; 'Jane'; 'Bob'};
ages = [30; 25; 35];
table_data = table(names, ages, 'VariableNames', {'Name', 'Age'});
A
Use table() function with data arrays and variable names to create tabular data structure with named columns for spreadsheet-like data organization
B
Use struct() for table creation
C
Tables are created automatically
D
Table creation is not supported
6

Question 6

How do you access table columns?

matlab
T = table({'John'; 'Jane'}, [30; 25], 'VariableNames', {'Name', 'Age'});
names = T.Name;
A
Use dot notation with column name to access table columns, providing intuitive data extraction from tabular structures with named variables
B
Use parentheses for column access
C
Use curly braces for table access
D
Table columns cannot be accessed
7

Question 7

What does the struct function do?

matlab
person = struct('name', 'John', 'age', 30, 'city', 'Boston');
A
struct() creates structure with field name-value pairs, providing programmatic structure creation with multiple fields in single function call
B
struct() creates tables
C
struct() modifies existing structures
D
Struct function is not supported
8

Question 8

How do you access table rows?

matlab
T = table({'John'; 'Jane'}, [30; 25], 'VariableNames', {'Name', 'Age'});
first_row = T(1, :);
A
Use parentheses with row indices and colon to access table rows, enabling standard array indexing for tabular data extraction and manipulation
B
Use dot notation for row access
C
Rows are accessed automatically
D
Table row access is not supported
9

Question 9

What is the fieldnames function used for?

matlab
person.name = 'John';
person.age = 30;
fields = fieldnames(person);
A
fieldnames() returns cell array of structure field names, enabling dynamic field discovery and programmatic access to structure contents
B
fieldnames() creates new fields
C
fieldnames() modifies field values
D
Field names function is not supported
10

Question 10

How do you add new fields to a structure?

matlab
person.name = 'John';
person.age = 30;
person.city = 'Boston';
A
Use dot notation with new field name and assignment to dynamically add fields to existing structure, expanding data organization capabilities
B
Use addfield() function
C
Fields are added automatically
D
Structure fields cannot be added
11

Question 11

What does the isfield function check?

matlab
person.name = 'John';
has_age = isfield(person, 'age');
A
isfield() checks if specified field exists in structure, enabling conditional field access and validation in dynamic structure operations
B
isfield() creates new fields
C
isfield() modifies field values
D
Field existence checking is not supported
12

Question 12

How do you sort a table by a column?

matlab
T = table({'John'; 'Jane'; 'Bob'}, [30; 25; 35], 'VariableNames', {'Name', 'Age'});
sorted_T = sortrows(T, 'Age');
A
Use sortrows() function with table and column name to sort table rows based on specified column values for data organization and analysis
B
Use sort() for table sorting
C
Tables are sorted automatically
D
Table sorting is not supported
13

Question 13

What is an array of structures?

matlab
people(1).name = 'John';
people(1).age = 30;
people(2).name = 'Jane';
people(2).age = 25;
A
Array of structures contains multiple structure elements, each with same fields, enabling collection of related structured data with consistent field organization
B
Array of structures is a regular array
C
Arrays of structures are not supported
D
Array of structures stores only one element
14

Question 14

How do you remove fields from a structure?

matlab
person.name = 'John';
person.age = 30;
person = rmfield(person, 'age');
A
Use rmfield() function with structure and field name to remove specified fields, enabling dynamic structure modification and cleanup
B
Use delete() for structure fields
C
Fields are removed automatically
D
Structure field removal is not supported
15

Question 15

What does the height function return for tables?

matlab
T = table({'John'; 'Jane'}, [30; 25], 'VariableNames', {'Name', 'Age'});
num_rows = height(T);
A
height() returns number of rows in table, providing essential table dimension information for data processing and validation operations
B
height() returns number of columns
C
height() calculates row height
D
Table height is not supported
16

Question 16

How do you create tables from arrays?

matlab
data = [1 2; 3 4; 5 6];
T = array2table(data, 'VariableNames', {'Col1', 'Col2'});
A
Use array2table() function to convert numeric arrays to table format with specified column names, enabling structured data analysis on existing arrays
B
Use table() only for array conversion
C
Arrays convert to tables automatically
D
Array to table conversion is not supported
17

Question 17

What is the difference between structures and tables?

A
Structures organize data with named fields for single records, tables organize data with named columns for multiple records enabling different data relationship patterns
B
They are identical data types
C
Structures are for numbers, tables for text
D
Tables are not supported
18

Question 18

How do you filter table data?

A
Use logical indexing with table variables to filter rows based on conditions, enabling data subset extraction for focused analysis and processing
B
Use filter() function for tables
C
Table filtering is automatic
D
Table filtering is not supported
19

Question 19

What does the getfield function do?

A
getfield() retrieves structure field values using string field names, enabling dynamic field access and programmatic structure manipulation
B
getfield() creates new fields
C
getfield() modifies field values
D
Field retrieval is not supported
20

Question 20

How do you merge tables?

A
Use join() or outerjoin() functions to combine tables based on key variables, enabling relational data operations and comprehensive dataset creation
B
Use merge() function for tables
C
Tables merge automatically
D
Table merging is not supported
21

Question 21

What is the setfield function used for?

A
setfield() assigns values to structure fields using string field names, providing dynamic field modification capabilities for programmatic structure updates
B
setfield() creates new structures
C
setfield() retrieves field values
D
Field setting is not supported
22

Question 22

How do you add rows to a table?

A
Use table constructor with additional data or concatenation to add rows, enabling dynamic table growth for accumulating data records over time
B
Use addrow() function
C
Rows are added automatically
D
Table row addition is not supported
23

Question 23

What does the width function return for tables?

A
width() returns number of variables (columns) in table, providing column count information essential for table structure understanding and validation
B
width() returns number of rows
C
width() calculates column width
D
Table width is not supported
24

Question 24

How do you handle missing data in tables?

A
Use fillmissing() or rmmissing() functions to handle NaN and missing values in table variables, ensuring data quality for analysis and processing operations
B
Missing data is handled automatically
C
Use missing() function for tables
D
Missing data handling is not supported
25

Question 25

What is the struct2table function used for?

A
struct2table() converts structure array to table format, transforming field-based data into column-based tabular structure for enhanced data manipulation
B
struct2table() converts tables to structures
C
struct2table() creates structures
D
Structure to table conversion is not supported
26

Question 26

How do you group table data?

A
Use groupsummary() or findgroups() with splitapply() to group table data by variables and perform group-wise operations for categorical data analysis
B
Use group() function for tables
C
Table grouping is automatic
D
Table grouping is not supported
27

Question 27

What does the orderfields function do?

A
orderfields() reorders structure fields or table variables according to specified order, enabling customized data presentation and organization
B
orderfields() sorts field values
C
orderfields() creates new fields
D
Field ordering is not supported
28

Question 28

How do you convert tables to arrays?

A
Use table2array() to convert table to homogeneous numeric array or access individual columns for mixed data type handling and computational operations
B
Use array() function for table conversion
C
Tables convert to arrays automatically
D
Table to array conversion is not supported
29

Question 29

What is the table2struct function used for?

A
table2struct() converts table to structure array, transforming column-based data into field-based structure for different data access patterns
B
table2struct() converts structures to tables
C
table2struct() creates tables
D
Table to structure conversion is not supported
30

Question 30

How do you handle duplicate table rows?

A
Use unique() function on table to identify and remove duplicate rows, ensuring data integrity and preventing analysis bias from repeated entries
B
Duplicates are handled automatically
C
Use duplicate() function for tables
D
Duplicate handling is not supported
31

Question 31

What does the vartype function do?

A
vartype() creates subscript for accessing table variables by data type, enabling type-based column selection and grouped operations on similar data types
B
vartype() changes variable types
C
vartype() creates new variables
D
Variable type selection is not supported
32

Question 32

How do you pivot table data?

A
Use unstack() function to pivot table data from long to wide format, transforming categorical variables into separate columns for different data perspectives
B
Use pivot() function for tables
C
Table pivoting is automatic
D
Table pivoting is not supported
33

Question 33

What is the difference between struct arrays and cell arrays?

A
Struct arrays have consistent field names across elements, cell arrays can have completely different data types in each element providing different flexibility levels
B
They are identical data structures
C
Struct arrays are for numbers, cell arrays for text
D
Cell arrays are not supported
34

Question 34

How do you validate table data types?

A
Use vartype() with class() function to check and validate data types of table variables, ensuring data integrity for analysis operations
B
Data types are validated automatically
C
Use validate() function for tables
D
Table data type validation is not supported
35

Question 35

What does the summary function provide for tables?

A
summary() provides statistical summary of each table variable including data type, missing values, and descriptive statistics for quick data understanding
B
summary() creates new tables
C
summary() modifies table data
D
Table summary is not supported
36

Question 36

How do you handle nested structures programmatically?

A
Use dynamic field names with getfield() and setfield() functions to access and modify nested structure fields programmatically for flexible hierarchical data manipulation
B
Nested structures cannot be handled programmatically
C
Use nested() function for structures
D
Programmatic nested structure handling is not supported
37

Question 37

What is the table2cell function used for?

A
table2cell() converts table to cell array, extracting table data into cell format for maximum flexibility in data manipulation and processing
B
table2cell() converts cells to tables
C
table2cell() creates tables
D
Table to cell conversion is not supported
38

Question 38

How do you perform calculations on table columns?

A
Access table columns using dot notation and apply standard MATLAB functions, enabling direct computational operations on tabular data variables
B
Use calculate() function for table columns
C
Calculations are performed automatically
D
Table column calculations are not supported
39

Question 39

What does the isstruct function check?

A
isstruct() verifies if variable is a structure or structure array, enabling type validation in functions that expect structured data input
B
isstruct() creates structures
C
isstruct() modifies structures
D
Structure type checking is not supported
40

Question 40

Considering MATLAB's structured data capabilities as a whole, what fundamental advantage do tables provide compared to structures for data analysis workflows?

A
Tables provide integrated analysis ecosystem with built-in functions for sorting, filtering, grouping, and statistical operations on tabular data, creating comprehensive data analysis workflow that structures alone cannot match while maintaining named column access and type safety throughout operations
B
Faster processing speed
C
Automatic data conversion
D
Simpler syntax

QUIZZES IN Matlab