Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Question on multidimensional array

Subject: Question on multidimensional array

From: Paulo Guimaraes

Date: 15 Oct, 2012 18:54:08

Message: 1 of 4

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)?

Thanks

P.

Subject: Question on multidimensional array

From: James Tursa

Date: 15 Oct, 2012 19:09:14

Message: 2 of 4

"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

Subject: Question on multidimensional array

From: Paulo Guimaraes

Date: 15 Oct, 2012 19:24:14

Message: 3 of 4

"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.

Thanks

Subject: Question on multidimensional array

From: Loren Shure

Date: 16 Oct, 2012 19:11:06

Message: 4 of 4

"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/

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us