Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Question on multidimensional array
Replies: 3   Last Post: Oct 16, 2012 3:11 PM

 Messages: [ Previous | Next ]
 Loren Shure Posts: 1,067 Registered: 12/7/04
Re: Question on multidimensional array
Posted: Oct 16, 2012 3:11 PM

"Paulo Guimaraes" wrote in message
news:k5hnsu\$4r1\$1@newscl01ah.mathworks.com...

"James Tursa" wrote in message <k5hn0q\$184\$1@newscl01ah.mathworks.com>...
> "Paulo Guimaraes" wrote in message
> <k5hm4g\$r3s\$1@newscl01ah.mathworks.com>...

> > Dear colleagues, if I have a matrix A I can apply a condition and change
> > all elements of the matrix in a single line of code. As in
> >
> > A=[0, 12, 3; 9; 3;1];
> > A(A>3)=1
> > A=[0, 1, 3; 1; 3;1];
> >
> > Is there any similar option for multidimensional arrays (e.g., each
> > element of A is now determined by n numbers in which n>2)?

>
> The same exact syntax for 2D matrices also works for nD arrays.
>
> James Tursa

>>Sorry I was not clear, I want to apply the condition just to one of the
>>dimensions, not the entire object. For example, I want to do:

>>if A(:, :, 3)>1 than A(:,:,3)=1.

A(:,:,3) = min(1,A(:,:,3));

Loren
http://blogs.mathworks.com/loren/
http://www.mathworks.com/matlabcentral/

Date Subject Author
10/15/12 Paulo Guimaraes
10/15/12 James Tursa
10/15/12 Paulo Guimaraes
10/16/12 Loren Shure