



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Lab1: Introduction to MATLAB Material Type: Lab; Professor: Paris; Class: Lab for Lecture 001; Subject: Electrical & Computer Enginrg; University: George Mason University; Term: Spring 2009;
Typology: Lab Reports
1 / 7
This page cannot be seen from the preview
Don't miss anything!




ECE 201 – SECTION 202 Introduction to Electrical Engineering II Lab1: Introduction to MATLAB Carlos A. Palomo February 8, 2009
ECE 201: Introduction to Electrical Engineering II Lab1: Introduction to MATLAB I. Objective and Theoretical Background: In this lab we will learn the how to solve simple problem using MATLAB. We will learn how to create and manipulate matrixes and other simple MATLAB functions by solving some simple questions. II. Material and Equipment: MATLAB 9. III. Laboratory Data
1. Clear the memory. Make sure that no current variables exist.
clear 2. Generate a row vector A whose first element is 4 and second element is 7. A= [4 7] A = 4 7 3. Generate column vector B by transposing row vector A. What is the size of B? B= A' B = 4 7
Using the following command we are told in which row and column the 9 appears
[row_D, col_D] = find(D==9) row_D = 6 col_D = 3
7. Replace the element located at the 5th row and 4th column in D with a 4.
D(5, 4)= D = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8. Replace the first column in D with C. Does the number of rows change? D(:, 1)=C
No, the number of rows does not change, it’s just replaced?
9. Generate a row vector E that starts with the value 2, ends at 40 and has an increment between elements of 2. How many elements are in E?
E = [2:2:40] E = 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 10. Generate a vector F from the last 14 elements in E. What does the 3rd element of F equal? Make a 12x2 matrix called G by replacing the 3rd column of D with the column vector C. F= E(7:20) % also can be done by F=E(end-13:end) F = 14 16 18 20 22 24 26 28 30 32 34 36 38 40 Using the following code we can get that the 3rd^ element of F is 18. F(3) ans = 18 G=D G = B= A' B = 4 7 Using the following command we are told in which row and column the 9 appears >> [row_D, col_D] = find(D==9) row_D = 6 col_D = 3 7. Replace the element located at the 5th row and 4th column in D with a 4. >> D(5, 4)= D = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8. Replace the first column in D with C. Does the number of rows change? >> D(:, 1)=C ## D = No, the number of rows does not change, it’s just replaced? 9. Generate a row vector E that starts with the value 2, ends at 40 and has an increment between elements of 2. How many elements are in E? >> E = [2:2:40] E = 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 10. Generate a vector F from the last 14 elements in E. What does the 3rd element of F equal? Make a 12x2 matrix called G by replacing the 3rd column of D with the column vector C. >> F= E(7:20) % also can be done by F=E(end-13:end) F = 14 16 18 20 22 24 26 28 30 32 34 36 38 40 Using the following code we can get that the 3rd^ element of F is 18. >> F(3) ans = 18 >> G=D G = 0 1 1 1 1 1 1 1 1 1 1 1
13. List the directory of variables currently in memory. How many total bytes are used?
whos Name Size Bytes Class Attributes A 1x2 16 double B 2x1 16 double C 12x1 96 double D 12x12 1152 double E 1x20 160 double F 1x14 112 double G 12x12 1152 double H 1x12 96 double Grand total is 350 elements using 2800 bytes 14. How many total variables have been generated? who Your variables are: A B C D E F G H IV. Comments and Conclusions In this lab we have learn how to implement simple functions of MATLAB, by answering simple questions. Overall we have learn how to use functions to create matrixes, find elements in the matrix, change and edit matrixes, and find how much memory we are using.