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

Problem 32. Most nonzero elements in row Given the matrix a, return the index r

ID: 3578350 • Letter: P

Question

Problem 32. Most nonzero elements in row Given the matrix a, return the index r of the row with the most nonzero elements. Assume there will always be exactly one row that matches this criterion. Example: Input a 1 2 0 0 0 0 0 5 0 0 2 7 0 0 0 069 3 3 1 output r is 4 Solution BE MATLAB Documentation function r fullest row (a) 3 end Click submit to create a new solution. Submitting an incorrect solution will not display Submit your name to other players, and it does not affect your score By clickng Submit you agree to our Terms of Use

Explanation / Answer

A)

function r=fullest_row(a)
r=1
nz=0
nz1=0
[row,col]=size(a)
for i=1:row+1
nz1=0
for j=1:col+1
if(a(i,j)!=0)
nz1=nz1+1
end
end
if(nz1>nz)
nz=nz1
r=i
end
end
end

B)

function b=back_and_forth(n)
b=ones(n)
num=1
for i=1:n+1
for j=1:n+1
if(i%2==1)
b(i,j)=num
end
if(i2==0)
b(i,n-i+1)=num
end
end
num=num+1
end
end

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