problem1 Software Applications SP 18 MATLAB Exam Problem 1 Generate any square m
ID: 2293713 • Letter: P
Question
problem1
Software Applications SP 18 MATLAB Exam Problem 1 Generate any square matrix of odd dimensions (3x3, 5x5, 7x7, etc) with the following pattern of zeros and ones Vectorize the code as much as possible Demonstrate your code to the instructor before leaving the exam. . .The dimensions of the matrix are entered by the user Use a MATLAB function or a MATLAB script. Your code should work in general. . Example: Problem 2 Generate any square matrix of even dimesions (4x4, 6x6, 8x8, etc) with the following pattern of zeros and ones, which looks like the letter Z . Vectorize the code as much as possible. . Demonstrate your code to the instructor before leaving the exam. . The dimensions of the matrix are entered by the user. . Use a MATLAB function or a MATLAB script. . Your code should work in general. Example: 0 0 0 0 1 0Explanation / Answer
Problem 1 Code:
clear all;
clc;
% Enter the dimensions of the square matrix
dim = input('Enter the dimnesion of the matrix: ');
% Initally let all the elements be zero
Matrix = zeros(dim,dim);
% Making all the corner to be 1 according to the pattern given
for i = 1 : dim
if(mod(i,2)~=0)
Matrix(i,:) = 1;
elseif(mod(i,2)==0)
Matrix(:,i) = 1;
end
end
MatirxRequired = Matrix
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.