I'm new to MATLAB (and this website!) and I needed some help with a problem I had been assigned for class. I searched this website for similar MATLAB problems, but I didn't come across any. The problem is asking the user to return the biggest number which is next to a zero. In other words, write a function which takes a list/array of numbers as input and returns the largest number which is adjacent to a zero. For instance, if
a=[1 -2 3 4 0 5 6 0 -7], Output: y=6.
I tried to solve the problem using a somewhat complex function I found online, and it seems to work on MATLAB. However, it won't work on our automated online MATLAB grading system as the command "imdilate" isn't recognized:
x=[1 2 0 4 5 -6 0 7 0 8]
zero_mask = (x == 0);
adjacent_to_zero_mask = imdilate(zero_mask, [1 0 1]);
max_value_adjacent_to_zero = max(x(adjacent_to_zero_mask));
y=max_value_adjacent_to_zero
I wanted to ask, is there is much simpler method of solving this problem not involving "imdilate" or other similar functions? Thank you for your help, I really appreciate it!