How find each element in a vector that is equal to 0
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to write a function that will receive one vector as input argument. I then want that function to return the largest element of vec that is adjacent to an element with the value 0. How do I check each element in the vector for being equal to zero? Also how to I then compare the two elements on either side of the zero?
0 Kommentare
Antworten (1)
Image Analyst
am 24 Feb. 2019
Bearbeitet: Image Analyst
am 24 Feb. 2019
Hint:
zeroLocations = vec == 0
and movmax() or imdilate(). Note: be careful to be robust, like in the cases where 0 is the largest value in a 3-element window around the zero. Do you want the result at that location to be 0, or the next largest number? If it's the next largest number, like for [-3, 0, -5] you want -3, you can do that with imdilate() using a structuring element of [1, 0, 1]. I don't think movmax() can do that so it would give you 0 instead of -3.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!