varinouputs.m function a varinouputs (varargin) for n-1inargin if sum (size (varargin (n))) 2 sa varargin(n) > 3 -s+varargin(n): end end disp (Inargin nargout)) :| Q1: Answer all of the following (1-10). 1- We can use help and doC commands/functions to get information on how to use a function in MATLAB. 2- MATLAB variable names must start with a letter 3- An example of a built-in variable in MATLAB is pi ori 4- The result of the following command A-2*(3+2)/3^-1 in MATLAB is: A 5- If B-5+6i, then B' and transpose(B) commands are the same. True or False? False 6- Let a-[2, 4, 6] and b-[5; 2; 6]. Which of the following operations would not give an error? 30 a) a+b; b) a'-b; c) a.*b; d) b*a; e) a./b'; ) a. a; 7- IfC-[1, 5, 6, 10, 3, 8], then C(1)=. 8- IfD-[1, 2, 3; 4, 5, 6; 7, 8, 9], then sub2ind([3 3], [3 2]. [2 2])- [5 6) D(2,3)=, D(end-2)=3 9- The result of the following command E-0.1<0.2<0.3 in MATLAB is: E 10- We can access a persistent variable from outside a function. True or False? b, d, e and f C(end-2)-, 10 error C(1.5)= alse Q2: Rewrite the following MATLAB program in an efficient way to reduce the execution time and display the time it takes to be executed. Solution i Solution 2 tic tic v=round (rand (1,20)*10)+6; ml-max (v) ; m2-min (v); k=0; for n-1:length (v) if v(n-k)--ml 1I v (n-k)=-m2 viround(rand(1,20)"10)+6; veround(rand(1,20)"1o) 6; v(find(v-max(v) | v=min(v))-[): v(vamax(v) | vamin(v)-[): toc toc v (n-k) -); k-k+1; A-floor(rand(s.4)"as)'s e) A-[A(1.); ones(1,size(A,2); A(2end,)]; end end a) A(mod(A,2)t)A(mod(A,2)u)"a Qu: solution --> b) evennumber-numel(A(mod(A2)o); Q3: Define a 2-D array (matrix) "A" with a dimension of 5*4 and fill it with random integers in the range [5,30). Then: a) Multiply the odd numbers in the matrix A by 2, b) How many even numbers in the matrix A? c) Insert a row of ones after the first row of matrix A. Q4: Define a function, name it varinputs, that accepts variable number of inputs and returns the sum of the secalar elements that are greater than 3 and displays the number of input and output arguments set by the user. Q4 solution is at the top of this paper.
varinouputs.m function a varinouputs (varargin) for n-1inargin if sum (size (varargin (n))) 2 sa varargin(n) > 3 -s+varargin(n): end end disp (Inargin nargout)) :| Q1: Answer all of the following (1-10). 1- We can use help and doC commands/functions to get information on how to use a function in MATLAB. 2- MATLAB variable names must start with a letter 3- An example of a built-in variable in MATLAB is pi ori 4- The result of the following command A-2*(3+2)/3^-1 in MATLAB is: A 5- If B-5+6i, then B' and transpose(B) commands are the same. True or False? False 6- Let a-[2, 4, 6] and b-[5; 2; 6]. Which of the following operations would not give an error? 30 a) a+b; b) a'-b; c) a.*b; d) b*a; e) a./b'; ) a. a; 7- IfC-[1, 5, 6, 10, 3, 8], then C(1)=. 8- IfD-[1, 2, 3; 4, 5, 6; 7, 8, 9], then sub2ind([3 3], [3 2]. [2 2])- [5 6) D(2,3)=, D(end-2)=3 9- The result of the following command E-0.1<0.2<0.3 in MATLAB is: E 10- We can access a persistent variable from outside a function. True or False? b, d, e and f C(end-2)-, 10 error C(1.5)= alse Q2: Rewrite the following MATLAB program in an efficient way to reduce the execution time and display the time it takes to be executed. Solution i Solution 2 tic tic v=round (rand (1,20)*10)+6; ml-max (v) ; m2-min (v); k=0; for n-1:length (v) if v(n-k)--ml 1I v (n-k)=-m2 viround(rand(1,20)"10)+6; veround(rand(1,20)"1o) 6; v(find(v-max(v) | v=min(v))-[): v(vamax(v) | vamin(v)-[): toc toc v (n-k) -); k-k+1; A-floor(rand(s.4)"as)'s e) A-[A(1.); ones(1,size(A,2); A(2end,)]; end end a) A(mod(A,2)t)A(mod(A,2)u)"a Qu: solution --> b) evennumber-numel(A(mod(A2)o); Q3: Define a 2-D array (matrix) "A" with a dimension of 5*4 and fill it with random integers in the range [5,30). Then: a) Multiply the odd numbers in the matrix A by 2, b) How many even numbers in the matrix A? c) Insert a row of ones after the first row of matrix A. Q4: Define a function, name it varinputs, that accepts variable number of inputs and returns the sum of the secalar elements that are greater than 3 and displays the number of input and output arguments set by the user. Q4 solution is at the top of this paper.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 3 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY