【MATLAB基礎入門篇】
1. The default MATLAB variable type for numeric data is:
A. Single
B. Double
C. Cell
【解析】Double指雙精度型,MATLAB中數值數據的默認類型為double,答案選B。
2. (Select all that apply) Which of the following will create a scatter plot of frogs on the horizontal axis and GDP on the vertical axis, with red markers at the data points?
A. plot (GDP, frogs, 'ro')
B. plot (GDP, frogs, 'o', 'r')
C. plot (frogs, GDP, 'ro')
D. plot (frogs, GDP, 'red')
【解析】題目中要求橫軸為frogs, 縱軸為GDP, 數據點加紅色標記。根據plot函數語法,輸入參數依次為橫軸參數,縱軸參數,屬性參數。屬性包括顏色,線型和標記三個特征,所有屬性添加到一個單引號內即可,用MATLAB中規(guī)定符號表示,不限順序?!畆o’代表紅色圓圈標記,答案選C。
3. Given a vector x, what is the command to add 3 to each element, double that value, then sum all the resulting values?
A. sum (2*x+3)
B. sum (2*[x(k)+3])
C. sum [2*x+3]
D. sum (2*(x+3))
【解析】題目中要求向量x每個元素加3,即(x+3);然后計算兩倍的值,即2*(x+3);最后求和,調用sum函數,即sum(2*(x+3));答案選D。
4. (Select all that apply): Given a 2-by-3 matrix A and a 3-by-2 matrix B, which of the following operations are valid?
A. A + B
B. A. + B
C. A * B
D. A. * B
【解析】題目中A矩陣維數為2行3列,B矩陣維數為3行2列。根據矩陣運算規(guī)則,矩陣加法(+),點積(. *)運算要求A,B矩陣同維數,所以排除A和D. MATLAB中沒有(.+)運算符, 所以排除B. 矩陣乘法(*)要求A矩陣列數等于B矩陣行數,答案選C。
5. If x is a 20-by-5 table with variables “A”, “B”, “C”, “D”, and “E”, which are all numeric vectors, the command y = x(:,'C') will return:
A. A 20-by-1 numeric vector
B. A 20-by-1 table
C.A 20-by-5 numeric array
D. A 1-by-1 table
E. Anerror message
【解析】table是MATLAB中存儲表格數據的一種數據類型,小括號可以實現數組索引, x (:,'C')表示索引變量名為C的列向量,所以維數為20行1列,索引結果依然保持table數據類型。答案選B。
6. Which command renames the first variable in the table t from foo to bar?
A. t.bar = t.foo
B. t.VariableNames(1) = 'bar'
C. t.Properties.VariableNames{1} = 'bar'
D. VariableNames(t,1) = 'bar'
【解析】題目中要求重命名table t的第一個變量,根據MATLAB語法,t.Properties.VariableNames定義變量名屬性,{1}索引第一個變量,然后將新變量名bar賦值即可,答案選C。
7. What construction should you use to loop over a block of code an indefinite number of times?
A. if
B. for
C. switch
D. while
E. Logical indexing
【解析】if結構實現基于邏輯判斷的條件轉移,switch結構實現有限次數的條件轉移,for結構實現有限次數循環(huán),while結構實現不限次數循環(huán),logical indexing實現條件數據查找,答案選D。
8. Which of the following is a validfunction declaration?
A. function [x,y] = foo(a,b)
B. function foo(a,b) = [x,y]
C. [x,y] = function foo(a,b)
D. [x,y] = foo(a,b)
【解析】MATLAB中函數聲明語法如下:
function [out1,out2,...] = function_name(in1,in2,...)
答案選A。
更多問題,微信小編在評論區(qū)等你~