Please help need codes The objective of this lab is to learn
Please help!!!!!!!!!!!!!!!!!!
need codes
The objective of this lab is to learn about different MATLAB functions which operate on complex numbers.
1. Download the file Complex.mat from Blackboard and place it in the current directory of MATLAB.
2. Open a new M-File in the MATLAB editor and name it Lab03.m.
3. Be sure that the workspace has been cleared of all variables and close all the figure windows.
4. Load the content of the file Complex.mat into the workspace. There should be a matrix called CompMatrix in the workspace after loading the file.
5. Find the dimensions of CompMatrix, save the number of rows in a variable named R1 and the number of columns in another variable named C1.
6. Ask the user to input an integer number as a guess for the number of rows and another integer as a guess for the number of columns. Store the first entered number in a variable named R2 and the second one in a variable called C2.
7. Use an if statement to perform different operations based on the entered values:
(a) If either of the entered values is negative or zero, display a message in the command window
saying that the number of rows and columns must be positive.
(b) If both values are less than the matrix dimensions, extract a sub-matrix which includes rows number 1 to R2 and columns number 1 to C2 of CompMatrix. Store the extracted sub-matrix in a variable called NewCompMatrix1. Extract another sub-matrix from the intersection of the remaining rows and columns of CompMatrix and store it in a variable called NewCompMatrix2. Plot the elements of the first sub-matrix by black square- shaped markers of size 6 and green face colors. On the same figure, plot the elements of the second sub-matrix by black o-shaped markers of size 6 and red face colors. Label the x and y axes Real Part and Imaginary Part respectively. Generate a title for the plot which shows numerical values of R2 and C2.
(c) If R2 is less than the number of rows of CompMatrix and C2 is greater than the number of columns of CompMatrix, store the last R2 rows of CompMatrix in a variable called LastRows. Use MATLAB built-in functions real and imag to calculate the real and imaginary parts of the elements of LastRows. Store the real and imaginary parts in variables called RealParts and ImaginaryParts respectively. Save these two variables in a .mat file called RealImaginary.
(d) If C2 is less than the number of columns of CompMatrix and R2 is greater than the num- ber of rows of CompMatrix, store the last C2 columns of CompMatrix in a variable called LastCols. Find proper MATLAB built-in functions, which calculate the magnitude and phase of complex numbers. Then, calculate the magnitude and phase of the elements of LastCols. Store the magnitudes and phases in variables called Magnitudes and Phases respectively. Save these two variables in a .mat file called MagnitudePhase.
(e) If both entered values are equal to the matrix dimensions, generate a complex variable called CompNumber whose real part is equal to R2 and the imaginary part to C2. With- out using MATLAB built-in functions of part (d) (using real and imag functions along with the formulas for magnitude and phase of complex numbers), calculate the magnitude and phase of CompNumber and store them in variables called CompNumberMag and CompNumberPh respectively. Save these three variables in a .mat file called Com- plexNumber.
(f) If both entered values are greater than the matrix dimensions, display a message in the command window saying that the row and column numbers are outside of the expected range.
8. Test your code by running the M-File and entering a variety of row and column numbers. Make sure all of the if statement sections produce proper results. If your code works as it should, you will find a total of four .mat files (including Complex.mat) in the current directory of MATLAB.
For your report, include your well-commented MATLAB code (M-File content), two plots with two different combinations of row and column numbers, magnitude and phase values calculated in part 7(e), and displayed messages in the command window in parts 7(a) and 7(f) .
Solution
(1) I have generated random complex numbers and downloaded to current directory.
N=1000;
M=10000000/N;
for jj=1:M
r=rand(N,1)*2*pi;
p=cos(r)+sin(r)*1i;
end
save \'Complex.mat\' p % p variable saved in Complex.mat
(2) Opend New file and named as Lab03.m
(3)
clc;
clear all;
close all;
(4)
load Complex.mat
Comp_Matrix=p;
(5)
[R1 C1]=size(Comp_Matrix);

