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.
What is in it
- Given B = [10,20,30;40,50,60], what does B(1,3) return?Answer: 30
- 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?Answer: It deletes the entire second column from A, leaving A = [1,3;4,6;7,9], a 3-by-2 matrix.
- 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?Answer: You reversed the index order; A(3,2) returns row 3, column 2, not row 2, column 3.
- For the matrix M = [3,6,9;12,15,18], what does size(M) return, and what does size(M,2) return?Answer: size(M) returns [2, 3] (2 rows, 3 columns). size(M,2) returns 3, the number of columns.
- What is a matrix, in terms of rows and columns, and how is [1,2;3,4;5,6] classified (size and shape)?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…
- Given v = [7, 14, 21, 28, 35], what does v(end) return, and what does v(end-1) return?Answer: v(end) returns 35 (the last element). v(end-1) returns 28 (the second-to-last element).
- If r = [1, 2, 3] is a row vector, what does r' (r followed by an apostrophe) produce, and what is its size?Answer: r' produces the column vector [1;2;3], a 3-by-1 matrix.
- What does the command x = 2:3:14 produce, and how many elements does it contain?Answer: x = [2, 5, 8, 11, 14], a 1-by-5 row vector.
- 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?Answer: MATLAB throws an error, commonly 'Undefined function or variable,' displayed in red/orange text in the Command Window.
- 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?Answer: Look at the scrollbar on the right edge of the editor for a red marker/X, then click or hover over it (or the…
and 7 more — open the set to see every question and its worked explanation.