f

#### diagonal of matrix

```Hi all,

Is there a non-loop way of obtaining the digonal elements Aii from a
matrix A and put them in a vector?

A=rand(60);
vd=digonal_elements_of(A) %vd is a vector

Thanks,
Per
```
 0
sunkan (358)
11/4/2004 4:10:23 PM
comp.soft-sys.matlab 211266 articles. 22 followers. lunamoonmoon (257) is leader.

5 Replies
321 Views

Similar Articles

[PageSpeed] 59

```Look for
the 'diag'-function

thomas

Per S wrote:
>
>
> Hi all,
>
> Is there a non-loop way of obtaining the digonal elements Aii from
> a
> matrix A and put them in a vector?
>
> A=rand(60);
> vd=digonal_elements_of(A) %vd is a vector
>
> Thanks,
> Per
```
 0
11/4/2004 4:24:28 PM
```thomas wrote:
>
>
> Look for
> the 'diag'-function
>
> thomas

Ok thanks,
I didn't know it was "reversal"

Thanks
Per
```
 0
sunkan (358)
11/4/2004 4:28:18 PM
```"Per S" <sunkan@fy.chalmers.se> wrote:

> Is there a non-loop way of obtaining the digonal elements Aii from a
> matrix A and put them in a vector?

You can obtain "getdiag" and "setdiag" here:

http://home.online.no/~pjacklam/matlab/software/util/matutil/getdiag.m
http://home.online.no/~pjacklam/matlab/software/util/matutil/setdiag.m

Peter

--
Why is the word "random" always spelt the same way?
```
 0
pjacklam (309)
11/7/2004 12:21:30 PM
```Why not simply use the built in MATLAB function diag?

a = diag(A); gives you a vector. diag(a), when a is a vector gives you a
diagonal matrix.

Or did I miss parts of the post with the original question?

/Johan

Peter J. Acklam wrote:

> "Per S" <sunkan@fy.chalmers.se> wrote:
>
>
>>Is there a non-loop way of obtaining the digonal elements Aii from a
>>matrix A and put them in a vector?
>
>
> You can obtain "getdiag" and "setdiag" here:
>
>   http://home.online.no/~pjacklam/matlab/software/util/matutil/getdiag.m
>   http://home.online.no/~pjacklam/matlab/software/util/matutil/setdiag.m
>
> Peter
>
```
 0
11/7/2004 12:40:06 PM
```Johan Carlson <Johan.NOSPAM.Carlson@csee.ltu.se> wrote:

> Why not simply use the built in MATLAB function diag?

It should do the trick for the original poster, but I avoid it
because it is ambiguous.

Peter

--
Why is the word "random" always spelt the same way?
```
 0
pjacklam (309)
11/7/2004 4:13:23 PM
 Reply: