indexing a set in an array

조회 수: 1 (최근 30일)
Paul Gendron
Paul Gendron 2021년 1월 18일
댓글: Paul Gendron 2021년 1월 22일
Dear users, Im trying to find a fast way to index a set of elements of an array that meet some criteria. For instance, Imagine that I have an array A=zeros(Nx,Ny) Nx=1000;Ny=1000. so A(k,l)=0 for all k,l<1000. Now I would like the set of indices, call them SET, that fullfill (k-ko)^2+(l-lo)^2<R^2 From which I can A(SET)=1. In this way with any given distance function I can build indicator functions for arbitrary sets.
  댓글 수: 4
Adam Danz
Adam Danz 2021년 1월 22일
Looks like Matt J hit the nail on the head. ✅
Paul Gendron
Paul Gendron 2021년 1월 22일
He really did, that deal() function is a gem and time saver. Thanks again Matt.

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

채택된 답변

Matt J
Matt J 2021년 1월 19일
[k,l]=deal(1:1000);
SET=(k.'-k0).^2+(l-lo).^2 < R^2;
  댓글 수: 1
Paul Gendron
Paul Gendron 2021년 1월 21일
Just fantastic, thanks Matt!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by