【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中规定符号表示,不限顺序。‘ro’代表红色圆圈标记,答案选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列。根据矩阵运算规则,矩阵加法(+),点积(. *)运算要求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结构实现有限次数循环,while结构实现不限次数循环,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。 更多问题,微信小编在评论区等你~ |
|