deleting some of the arrays in a matrix based on a principle
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pooneh Shah Malekpoor
le 28 Fév 2022
Modifié(e) : Matt J
le 28 Fév 2022
Hello
I have a matrix of numbers for example: [10; 20; 30; 40; 50; 60; 70; 80; 90;...;160] which are assigned to a mesh in order, the same as the figure below(element size=10). I want to delete the numbers: 40, 80, 120, 160 based on a line which intersects this mesh and only retain [10;20;30;50;60;70;90;100;110;130;140;150] to be my output. How can I code this? Any suggestion is highly appreciated.
Best Regards
Pooneh![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/909715/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/909715/image.jpeg)
3 commentaires
Réponse acceptée
Matt J
le 28 Fév 2022
Modifié(e) : Matt J
le 28 Fév 2022
A=reshape(10:10:160,4,4)
[M,N]=size(A);
[X,Y]=ndgrid(0:M-1,0:N-1);
test=@(x,y) y+4*x-12<=-1e-6; %test if x,y is below the line with 1e-6 tolerance.
keep=test(X,Y)|test(X+0.5,Y)|... %keep a cell if any of its 4 corners is below the line
test(X,Y+0.5) | test(X+0.5,Y+0.5);
result=A(keep)' %[10;20;30;50;60;70;90;100;110;130;140;150]
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!