Problem 16. Return the largest number that is adjacent to a zero giving me error on my correct code

Nabil Miri on 17 Mar 2020
Latest activity Reply by Nabil Miri on 19 Mar 2020

In problem 16 I used the following solution:
function b = nearZero(a)
b = max(a(imdilate(a == 0, [1 1 1])));
end
It is working pretty well on mathlab but when I submit my answer to cody, the following error is generated:
Undefined function 'imdilate' for input arguments of type 'double'.
Error in nearZero (line 2)
b = max(a(imdilate(a == 0, [1 1 1])));
Error in Test1 (line 3)
assert(isequal(nearZero(a),b))
Image Analyst
Image Analyst on 17 Mar 2020
That function is in the Image Processing Toolbox, which evidently you do not have. Type
>> ver
to see what toolboxes you have installed.
Try this to verify whether or not you have the Image Processing Toolbox installed:
% Check that user has the specified Toolbox installed and licensed.
hasLicenseForToolbox = license('test', 'image_toolbox'); % Check for Image Processing Toolbox.
% hasLicenseForToolbox = license('test','Statistics_toolbox'); % Check for Statistics and Machine Learning Toolbox.
% hasLicenseForToolbox = license('test','Signal_toolbox'); % Check for Signal Processing Toolbox.
% hasLicenseForToolbox = license('test', 'video_and_image_blockset'); % Check for Computer Vision System Toolbox.
if ~hasLicenseForToolbox
% User does not have the toolbox installed, or if it is, there is no available license for it.
% For example, there is a pool of 10 licenses and all 10 have been checked out by other people already.
ver % List what toolboxes the user has licenses available for.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
Nabil Miri
Nabil Miri on 19 Mar 2020
Thanks. The movmax() function has worked.
b = max(nonzeros(a(movmax(a == 0, [1 1])))')
Image Analyst
Image Analyst on 17 Mar 2020
imdilate is basically a moving max filter, so see if you can replace imdilate with movmax().
Nabil Miri
Nabil Miri on 17 Mar 2020
In my matlab it is working but in the cody challenge compiler on the matlab website it is not.