ECE 201 Introduction to Signal Analysis Fall 2016 Lab 1 Int

ECE 201 - Introduction to Signal Analysis

Fall 2016

Lab 1: Introduction to MATLAB

In this assignment, you will generate a matrix which contains grades of 5 students for 3 tests. You

will learn how to replace the elements in a matrix, convert row vectors to column vectors, nd

certain values in a matrix, etc. To generate a report of your work start a diary le called LAB ONE

by typing diary LAB ONE at the command prompt. All your MATLAB commands as well as the

answers you get will be captured in the diary le.

1. Clear the memory. Make sure that no current variables exist.

2. Generate a 5 4 matrix with all elements equal to zero. Name the matrix ClassGrade.

3. Generate a row matrix called Names which contains students names. The names are just

integers from 1 to 5.

4. Convert the matrix Names to a column vector called Names col.

5. Replace the rst column of ClassGrade with Names col.

6. The rst exam grades are as follows:

FirstExamGrade = [ 60 85 90 NaN 100 ];

Convert FirstExamGrade to a column vector and put it as a second column of ClassGrade.

7. The second and third exam grades are as follows:

SecondT hirdGrades = [ 70 NaN 85 95 98 ; 65 79 86 90 NaN ];

Put these grades into the 3rd and 4th columns of ClassGrade.

8. The NaN (Not a Number) element means that particular student was absent on the test.

Replace all the NaNs with 0s.

9. We would like to have a matrix with grades only. Extract the sub matrix containing all the

rows but only columns number 2 through 4. Name the new matrix GradesOnly.

10. Extract from ClassGrade the sub matrix which only contains the student names. Name the

new matrix NamesOnly.

Solution

clear all; %step1

Classgrade=zeros(5,4); %step2

names=[1 2 3 4 5]; %step 3

namescol=names\'; %step4

Classgrade(:,1)=namescol; %step5

firstexamgrade=[60 85 90 NaN 100]; %step6

Classgrade(:,2)=firstexamgrade\';

secondthirdgrades=[70 NaN 85 95 98; 65 79 86 90 NaN]; %step 7

Classgrade(:,3:4)=secondthirdgrades\';

Classgrade(isnan(classgrade))=0; %step8

gradesonly=Classgrade(:,2:4); %step9

namesonly=Classgrade(:,1); %step10

ECE 201 - Introduction to Signal Analysis Fall 2016 Lab 1: Introduction to MATLAB In this assignment, you will generate a matrix which contains grades of 5 stud
ECE 201 - Introduction to Signal Analysis Fall 2016 Lab 1: Introduction to MATLAB In this assignment, you will generate a matrix which contains grades of 5 stud

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site