pewter_cauldron
pewter_cauldron

Reputation: 73

Referring to coordinates of a 3d matrix in Matlab

In Matlab I'm trying to find points in a 3d matrix whose coordinates are smaller than some function. If these coordinates are equal to some functions than I can write:

A(some_function1,some_function2,some_function3)=2;

But what if I want to do something like:

A(<some_function1,<some_function2,<some_function3)=2;

This isn't working - so what is the other way of finding such points without using "for" loop? Unfortunately with "for" loop my code takes a lot of time to compute. Thank you for your help!

Upvotes: 1

Views: 327

Answers (3)

ely
ely

Reputation: 77484

You can just use regular indexing to achieve this:

A(1:floor(some_function1),1:floor(some_function2),1:floor(some_function3)) = 2;

assuming you check / ensure that floor(some_function*) is smaller than the dimensions of A

Upvotes: 1

learnvst
learnvst

Reputation: 16195

How about something along the lines of

A(  ceil(min(some_function1,size(A,1))),...
    ceil(min(some_function2,size(A,2))),...
    ceil(min(some_function3,size(A,3)))   );

This will cap the indicies to the end of each array dimension

Upvotes: 1

Tal Darom
Tal Darom

Reputation: 1409

Try:

A(1:size(A,1)<some_function1, 1:size(A,2)<some_function2, 1:size(A,3)<some_function3) = 2

I hope I got your question correctly.

Upvotes: 0

Related Questions