For this assignment, the function will take in a matrix of unknown size. Write a
ID: 2080440 • Letter: F
Question
For this assignment, the function will take in a matrix of unknown size. Write a function that returns false(0) if any edge value is a zero. Otherwise, return a matrix or size equal to the original matrix that has a zero for any non-zero position or the largest number that is adjacent (in contact) to a zero. Instructions: To solve this problem, modify the template bellow with your code. Leave the names of the function and variables unchanged. Also maintain the names of the sub-functions. Otherwise your code will not pass the test. Click Test to test your solution before submitting it. When you are satisfied with it click Submit.Explanation / Answer
Objective:
largest number next to zero.
Condition : 1 should not end of the matrix because code cant find the value in the edge
Condition : 2 Keep or return the matrix size from its orginal matrix.
version: MatlabR2013a
function [ matout ] = nearzero( matin )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
% matin =[ 1 2 3 4; 5 6 0 8; 9 2 5 2];
%matin = [1 2 -4; 0 0 -5; 4 -2 0; 1 0 6];
matin = [1 2 3 ; 01 0 80 ; 0 4 0; 0 0 -6; 0 0 9];
% step: 1
nz_values = find(matin~=0); % To find the zero value in the matrix--To catch its position
% step: 2
nz_postion_check = [nz_values-1 nz_values+1]; % to check in the matrix,the first and last position value NOT equal to the non zero adjcent value
% step: 3
% (maxcandidates > 0) --> to check the values , (maxcandidates <= length(matin)) this condtion to avoid last non-zero value
nz_postion_check = nz_postion_check((nz_postion_check > 0) & (nz_postion_check <= length(matin)));
non_z= matin(nz_postion_check)~=0; % find non zero value within those two conditions
% pos= find(max(matin(found_nz_pos_adj(non_zero))))
matout = max(matin(nz_postion_check(non_z)));
end
Answer :
matout =
1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.