Shared set · @asarrett · MATLAB / Introductory Programming (EGR 219 Onramp)
MATLAB Fundamentals: Variables, Scripts, Vectors, and Matrices
Topics drawn from a student's MATLAB Onramp reflection notes (variable recalculation, comments, error messages, vectors and matrices); questions are written from standard MATLAB fundamentals.
Save a copy to my library — freeOpen in Chalkset
17 questions with worked explanations. Or make your own from your notes — the first draft needs no account.
Try the first 5 cards
1 of 17
Given B = [10,20,30;40,50,60], what does B(1,3) return?
tap to reveal the answer
30
Indexing is always (row, column). Row 1 is [10,20,30], and its 3rd element is 30.
2 of 17
Given A = [1,2,3;4,5,6;7,8,9], what does the command A(:,2) = [] do to A, and what is the resulting size?
tap to reveal the answer
It deletes the entire second column from A, leaving A = [1,3;4,6;7,9], a 3-by-2 matrix.
Assigning empty brackets [] to a row or column selector removes that row/column entirely from the matrix, rather than setting values to zero or leaving a gap. Here A(:,2) refers to the whole second column, so deleting it shifts the third column into its place, reducing A from 3-by-3 to 3-by-2.
3 of 17
If you accidentally write A(3,2) intending to get row 2, column 3 of a matrix A, what mistake have you made and what will actually be returned?
tap to reveal the answer
You reversed the index order; A(3,2) returns row 3, column 2, not row 2, column 3.
MATLAB indexing is strictly (row, column), so swapping the numbers accesses a completely different element unless the matrix happens to be symmetric at those positions.
4 of 17
For the matrix M = [3,6,9;12,15,18], what does size(M) return, and what does size(M,2) return?
tap to reveal the answer
size(M) returns [2, 3] (2 rows, 3 columns). size(M,2) returns 3, the number of columns.
size(M) gives a two-element vector [rows, columns] describing the matrix's dimensions. Supplying a second argument (the dimension number) returns just that dimension's length: dimension 1 is rows, dimension 2 is columns, so size(M,2) isolates the column count, 3.
5 of 17
What is a matrix, in terms of rows and columns, and how is [1,2;3,4;5,6] classified (size and shape)?
tap to reveal the answer
A matrix is a rectangular array with more than one row and more than one column; [1,2;3,4;5,6] is a 3-by-2 matrix (3 rows, 2 columns).
Each semicolon starts a new row, and within a row, commas separate columns. Counting the rows (3) and the columns (2) gives the size, always stated as rows-by-columns.
12 more in the set. Keep going in Chalkset — each card is scheduled on its own, so the ones you miss come back sooner.
Also in this set
- Given v = [7, 14, 21, 28, 35], what does v(end) return, and what does v(end-1) return?
- If r = [1, 2, 3] is a row vector, what does r' (r followed by an apostrophe) produce, and what is its size?
- What does the command x = 2:3:14 produce, and how many elements does it contain?
- You type a variable name that was never created (e.g., due to a typo) into the Command Window. What happens, and what color does MATLAB typically use to flag it?
- In the MATLAB editor, where do you look to quickly locate a line with an error, and how do you see the actual error message?
and 7 more — open the set to see every question and its worked explanation.