Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Swap elements in a matrix

$
0
0
On 11/20/2012 10:39 PM, Jinsoo wrote:
> Hi,
>
> I have a question about swapping elements in a matrix. I would like to swap elements
>in the matrix without making a new matrix. Though I googled about any functions,
>I failed to find out. Below is the example that shows my intent.
>
> a = [ 3 1 2
> 2 1 1
> 5 4 4 ]
>
> I want to change a(1,2) -> a(2,1) and a(2,1)->a(1,2). The edited matrix a will be like this.
>
> a= [ 3 2 2
> 1 1 1
> 5 4 4]
>
> Your words will be highly appreciated! Enjoy your Thanksgiving!
>


--------------------
tmp=a(1,2); a(1,2)=a(2,1); a(2,1)=tmp
-------------------

a =

      3 2 2
      1 1 1
      5 4 4

Viewing all articles
Browse latest Browse all 19628

Trending Articles