필터 지우기
필터 지우기

is it possible to vectorise the following. I want to construct all pairs of integers (I,j) with i^2 + j^2 <= r^2, This includes negative i and j. Ideally I want a 2 by k matrix listing my pairs in lexicographic order. At the moment I use for loops.

조회 수: 1 (최근 30일)
Given r, I want to construct all pairs of integers (i,j) with i^2 + j^2 <= r^2, This includes negative i and j. Ideally I want a k by 2 matrix listing my pairs in lexicographic order (either i_1 < i_2 or i_1==i_2 and j_1 < j_2). Can this be vectorised in Matlab? At the moment I use for loops, which doesn't matter, because I don't have to do it often. But I'm thinking a might need the fastest possible method for doing something similar in another program.
  댓글 수: 2
David Epstein
David Epstein 2018년 7월 20일
I should have said that I am using Matlab R2018a on a MacBook Pro running MacOS 10.13.6
David Epstein
David Epstein 2018년 7월 20일
mostly quite small at the moment (up to around 20), but I might contemplate going up to r=200. However, in that case someone would probably do the programming for me in python or C++ on a very large and powerful machine.

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

채택된 답변

James Tursa
James Tursa 2018년 7월 20일
One way:
[x,y] = meshgrid(-r:r,-r:r);
z = x.*x + y.*y <= r*r;
result = [x(z) y(z)];

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by