Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Note: i JUST NEED HELP with the MATLAB Part (ONLY THIS)... I already performed t

ID: 2082024 • Letter: N

Question


Note:
i JUST NEED HELP with the MATLAB Part (ONLY THIS)... I already performed the others calculation by my self in handwriting.
thanks!!

Problem 3 Given a square matrix Mofodd dimensions (3 by 3.5 by 5 or larger in general lcenterdiamond diamond (M) he example. should remain anchanged. You should preserve the original matrix Use any method. Your code should work in general with any square ample i 0 4 Example 2 2 4 2 53 5 3 2 3 4 3 54 3 3 3 3 3 2 27 4 6 2 Becomes: 2 2 5 3 0 3 0 4 3 0 3 5 0 3 0 3 0 2 6 0 4 6 2

Explanation / Answer

Ans)

Matlab code here

============

function [centerdiamond] = centerdiamond( M )
%CENTERDIAMOND Summary of this function goes here
% Detailed explanation goes here

centerdiamond=M; %copy the given matrix
[r,c]=size(M);%size of matrix returns no of rows and columns
for i=1:r
  
if i==1
centerdiamond(i,((c+1)/2))=0;%make center element of first row =0   

elseif i<=((r+1)/2) %upto center of rows
  
centerdiamond(i,((c+1)/2)-(i-1))=0;
centerdiamond(i,((c+1)/2)+(i-1))=0;
  
else %from center of rows to end
centerdiamond(i,(1+(i-((r+1)/2))))=0;

centerdiamond(i,(c-(i-((r+1)/2))))=0;
  
end
  
end

end

====================

Result obtained

======

>> M=[1 3 2 4 2;5 7 8 9 5;3 2 4 6 3;6 8 2 1 3;3 3 3 3 3];
>> M

M =

1 3 2 4 2
5 7 8 9 5
3 2 4 6 3
6 8 2 1 3
3 3 3 3 3

>> centerdiamond(M)

ans =

1 3 0 4 2
5 0 8 0 5
0 2 4 6 0
6 0 2 0 3
3 3 0 3 3

>>

==============================

Result of random matrix of size 7 by 7

==

>> centerdiamond(rand(7,7))

ans =

0.1233 0.4909 0.3897 0 0.1690 0.7447 0.0811
0.1839 0.4893 0 0.0598 0 0.1890 0.9294
0.2400 0 0.4039 0.2348 0.7317 0 0.7757
0 0.9001 0.0965 0.3532 0.6477 0.1835 0
0.0497 0 0.1320 0.8212 0.4509 0 0.4359
0.9027 0.1112 0 0.0154 0 0.6256 0.4468
0.9448 0.7803 0.9561 0 0.2963 0.7802 0.3063

>>

==================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote