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:

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

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -