Especificar valores de una matriz dentro de un poligono
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
José Juan Ibáñez Cemborain
il 25 Lug 2023
Buenas tardes.
Teniendo una matriz de 256x256 enteramente con valores 0.5.
Me gustaría ponerle un valor concreto (por ejemplo 0.8) a los valores de la matriz que estén dentro de una forma geometrica delimitada por unas coordenadas x e y.
Lo he intentado con regionfill pero no soy capaz.
Muchas gracias y quedo a vuestra disposción.
0 Commenti
Risposta accettata
Keshav
il 1 Ago 2023
To set specific values within a geometric shape in a matrix, you can use 'poly2mask' function. The 'poly2mask' function sets pixels that are inside the polygon to 1 and sets pixels outside the polygon to 0. Afterwards, you can utilize the logical indexing to assign the specific value in the matrix.
Below is a sample code for reference:
% Create a 256x256 matrix filled with 0.5 values
matrix = ones(256,256) * 0.5;
% Change the x and y coordinate according to your requirement.
x = [1, 10, 1, 10];
y = [5, 5, 15, 15];
% Create a logical mask for the shape
mask = poly2mask(x, y, 256, 256);
% Set the desired value (e.g., 0.8) within the shape
matrix(mask) = 0.8;
You can read more about 'poly2max' function in the below MathWorks documentation.
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!