multidimensional array - Can you define a variable in MATLAB like a set? -
i want able deal 3d structures in matlab. i'm new matlab, , haven't seen answer question after googling it.
if want define specific sphere explicitly, without using built in sphere function, how work? example, there way define variable r = (1,1,1) in xyz coordinate system, , define new variable/set s = {all s: distance (r,s) <= radius)}. immensely handy if that, i'm not sure how matlab deal that, involve infinite set of points, matlab have have defined maximum resolution. possible? great able define 3d structures in way. thank
if
all s: distance (r,s) <= radius)
you mean
all s in r3: distance (r,s) <= radius)
then answer is:
no, can't define set by extension (that is, enumerating elements), because set has uncountably infinitely many elements.
but can define set s by intension. means can build rule (a function) that, given value x in r3, tell if x in s or not.
namely, rule can built using anonymous function follows:
>> r = [1 1 1]; %// set center >> radius = 2; %// set radius >> ins = @(s) sqrt(sum((s-r).^2))<radius;
the function ins
returns true
(1
) if , if input belongs s, , false
(0
) otherwise. example,
>> ins([0 0 0]) ans = 1 >> ins([3 4 5]) ans = 0 >> ins([pi sqrt(2) exp(-1)]) ans = 0
this closest can "defining" set.
if want test several values @ once, instead of using loop can vectorize function bsxfun
:
>> ins = @(s) sqrt(sum((bsxfun(@minus, s, r)).^2, 2))<radius; >> points = [ 0 0 0 3 4 5 pi sqrt(2) exp(-1) ]; >> ins(points) ans = 1 0 0
Comments
Post a Comment