Finding the perimeter of a region of a matrix where the matrix is made of zeros and ones

8 visualizaciones (últimos 30 días)
Write a function, matrix_perimeter, that takes a matrix of ones and zeros as an input. Assume the length and width of each cell is 1. Your function should output the perimeter of the shaded area represented by ones in the input matrix. The matrix above should return 18 for the perimeter. Not real sure how to solve this after make a matrix

Respuestas (1)

Sam
Sam el 17 de En. de 2023
Editada: Sam el 18 de En. de 2023
look at this example. there is a matlab function for that:
Edges = bwperim(LogicalMatrix)
then apply a sum on edges
perimeter = sum(sum(Edges))

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by