EE215_Lab9_sol

pdf

School

California State University, Fullerton *

*We aren’t endorsed by this school

Course

215

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

6

Uploaded by MasterMonkey4142

Report
EE215 MATLAB LAB 9 Solutions Instructor: Dr. J. Huang Objective: This lab is to help students understand the use of different file formats in Matlab. In addition, the use of set, bit and base functions will also be covered in this lab. 1. Set, Bit and Base Functions First, create two sets of data in Matlab: A = [10 2 3 8 19 -10 -12]; B = [2 5 8 -12]; Fill in the following table by using the functions for Set operations. Function Result Function Result isequal(A, B) 0 intersect(A, B) -12 2 8 unique(A) -12 -10 2 3 8 10 19 setxor(A, B) -10 3 5 10 19 unique(B) -12 2 5 8 setdiff(A, B) -10 3 10 19 ismember(A, B) 0 1 0 1 0 0 1 setdiff(B, A) 5 ismember(B, A) 1 0 1 1 union(A, B) -12 -10 2 3 5 8 10 19 Next, create the following two variables using the hexadecimal format: a = 1234; b = 2015; The expressions are: Fill in the following table by using the functions for Bit operations. Function Result Function Result bitand(a, b) 04d2 bitxor(a, b) 030d bitor(a, b) 07df bitget(b, 5) 0001 bitcmp(a) fb2d bitset(a, 8) 04d2 Now, change the data format to regular format . Then, evaluate the following base conversion expressions: format short g Expression Result Expression Result a = dec2bin(28) 11100 class(b) double class(a) char b = dec2base(115, 4) 1303 1
bin2dec(a) 28 class(b) char a = dec2hex(218) DA base2dec(b, 4) 115 class(a) char b = hex2dec(a) 218 2. Storing and loading data from data files First, generate a vector of 10 elements, starting from 0, ending at 6. The expression for generating this vector is: x = linspace (0,6,10) Evaluate y1 = sin(x); y2 = cos(x); y3 = sin(2x); and y4 = sin(x) + cos(x/2). Suppose you want to save all variables to the default workspace, how do you do it? The expression is: save Suppose you want to clear all the variables in Matlab workspace, how do you do it? The expression is: clear all After you clear everything in the workspace, load y1 & y4 to the workspace from the default matlab data file. The expression for this is: load matlab y1 y4 Clear everything, then load everything back from the default matlab data file. The expression for this is: clear all; load Save y1 & y3 to data file ‘data1.mat’. The expression for this is: save data1 y1 y3 Save y2 & y4 to data file ‘data2.mat’. The expression for this is: save data2 y2 y4 Clear everything in the workspace again. Load y1 back from data file ‘data1.mat’ & y4 back from data file ‘data2.mat’. The expression for this is: clear all; load data1 y1; load data2 y4; Clear everything, then load everything back from the default matlab data file. Then, save x, y2 & y3 to one data file ‘datatxt.dat’ using ASCII format. The expression for this is: clear all; load; save datatxt.dat x y2 y3 -ASCII Open ‘datatxt.dat’ to check the contents of the file. 3. Import data and use low-level file Input/Output 2
Use xlsread to import data from the excel spread-sheet file: ‘weather1997.xls’. The expression for this task is: [data, txt] = xlsread ('weather1997.xls'); Based on the data you read from the excel file, create a figure with three subplots. The upper plot shall be the plot of max temperature versus the day of the year. The middle plot shall be the plot of min temperature versus the day of the year. The bottom plot shall be the plot of the daily temperature variation (max - min) versus the day of the year. Please title, label, legend and use color style appropriately. Your code for this task is: 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
The plot is: 0 50 100 150 200 250 300 350 400 20 40 60 80 100 High Temp (F) Weather Info From Year 1997 Daily High Temp 0 50 100 150 200 250 300 350 400 0 20 40 60 Low Temp (F) Daily Low Temp 0 50 100 150 200 250 300 350 400 0 10 20 30 40 50 Time (Day of year) Temp Variation (F) Daily Temp Variation Based on what you read from the excel file, can you find the highest temperature of the year? How do you do it? The expression is: Result is: Can you find out the corresponding day and date information for the date when the highest temperature was observed? Your code for this task is: Result is: 4
Can you also find the lowest temperature of the year? The expression for this task is: Result is: Can you find out the corresponding day and date information for the date when the lowest temperature was observed? Your code for this task is: Result is: *EXTRA CREDIT QUESTION Now, based on what you read from the excel file, save the selected weather data into a formatted ASCII file. The first few rows of the ASCII file will look like: Data for day, date, high temp, low temp, nominal high temp and nominal low temp shall be included in the ASCII file. In addition, you shall use tab space to separate the data fields. Your file shall include all the available weather data for the year of 1997. 5
Your code for this task is: Please submit the data file you generated along with this lab report to the digital dropbox. 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help