필터 지우기
필터 지우기

deleting some of the arrays in a matrix based on a principle

조회 수: 2 (최근 30일)
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor 2022년 2월 28일
편집: Matt J 2022년 2월 28일
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
  댓글 수: 3
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor 2022년 2월 28일
This is an example line drawn from the top corner of the highest elements to the bottom corner of the first row elements. This line shows the slope of the geometry which I am going to assign values to its elements.
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor 2022년 2월 28일
the final meshing of the geometry should be like this figure:

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2022년 2월 28일
편집: Matt J 2022년 2월 28일
A=reshape(10:10:160,4,4)
A = 4×4
10 50 90 130 20 60 100 140 30 70 110 150 40 80 120 160
[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]
result = 1×12
10 20 30 50 60 70 90 100 110 130 140 150

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by