필터 지우기
필터 지우기

Index of points which satisfy a given equation

조회 수: 3 (최근 30일)
Ali Baig
Ali Baig 2019년 8월 3일
댓글: Ali Baig 2019년 8월 3일
Hellow everyone,
I am working on a problem in which I have defined following variables:
NodesAlongOneDirection = 10
x1 = 0; x2 = 1; Nx = NodesAlongOneDirection; x = linspace(x1, x2, Nx); dx = x(2) - x(1);
y1 = 0; y2 = 1; Ny = NodesAlongOneDirection; y = linspace(y1, y2, Ny); dy = y(2) - y(1);
[X, Y] = meshgrid(x, y); X = X(:); Y = Y(:); N = length(X);
Now I want to find index of points (index of X, Y) which satisfy any given equation, say, Y = -X +1, which is equation of "secondary diagonal" of square domain.
I have tried following lines:
A = find(Y == -X +1);
But it doesn't contain all the points on secondary diagonal.
Regards,
Ali Baig
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 8월 3일
You should not be using floating point equality as it demands bit for bit exact comparisons. You should compare with a tolerance.
Ali Baig
Ali Baig 2019년 8월 3일
Dear Walter Roberson
Thank you for reply. Keeping what you have suggested, I have written the following lines:
Y_Low = -X + 1 - 0.25 * sqrt(dx^2 + dy^2);
Y_High = -X + 1 + 0.25 * sqrt(dx^2 + dy^2);
A = find(Y > Y_Low & Y < Y_High);
figure()
plot(X(A), Y(A), '*')
This works fine at least for points on secondary diagonal. The "0.25 * sqrt(dx^2 + dy^2)" is used as a tolerance value.
Once again, thank you so much for your help.
Regards,
Ali Baig

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by