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 月 18 日
If you show us what you've tried so far we can see if we can beat it.
Paul Gendron
Paul Gendron 2021 年 1 月 21 日
編集済み: Paul Gendron 2021 年 1 月 21 日
Thanks, so for instance it is quite easy in Matlab to create an indicator function for a rectangular set. M=30,P=40;Let Ix=ko+[-M:M], ly=lo+[-P:P], then A(lx,ly)=1 will created an indicator function over the rectangle of height 2M and width 2P. But now I would like a fast simple way to create indicator functions for other types of sets, discs, elipses etc. Not just rectangles.
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 日

0 投票

[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 件)

カテゴリ

ヘルプ センター および File ExchangePerformance and Memory についてさらに検索

タグ

質問済み:

2021 年 1 月 18 日

コメント済み:

2021 年 1 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by