0

How can I merge this two commands in one in Matlab?

Temp = diag(diag(A));
X = Temp(:)

Something like

X = diag(diag(A))(:) 

does not work.

user25004
  • 1,868
  • 1
  • 22
  • 47
  • seems Matlab's been lagging too much in [implementing that syntax](http://wiki.octave.org/FAQ#Coherent_syntax). It's valid in GNU Octave. – carandraug Nov 27 '12 at 23:59
  • See [how-can-i-index-a-matlab-array-returned-by-a-function-without-first-assigning-it](http://stackoverflow.com/questions/3627107/how-can-i-index-a-matlab-array-returned-by-a-function-without-first-assigning-it) for another solution. But really, it is more trouble than it is worth. – Colin T Bowers Nov 28 '12 at 00:10

1 Answers1

0

If you really want to, you can do:

X = reshape(diag(diag(A)),[],1)

I'm not sure you gain much by doing that though!

nbeuchat
  • 6,575
  • 5
  • 36
  • 50