I have a 5 x 5 matrix:
cdsSpread5yrs =
But after doing a row extract, why is it displaying as a column?
rowSpread2 = cdsSpread5yrs[[2]];
rowSpread2 // MatrixForm

|
I have a 5 x 5 matrix: cdsSpread5yrs =
But after doing a row extract, why is it displaying as a column?
|
||||
|
Think of it this way, a matrix is a rectangular set of elements: Now if I ask Mathematica to plot on matrix form both What you can do is that when you need to extract stuff write it out
This way you retain the information of whether it's a column or a row you are dealing with.
(And yes of cause in the first case |
|||||||||||||||
|
|
Well, to answer you comment I just wanted to say that Mathematica is really a very flexible language (may be too flexible:) If you do not like something, you could always write little code to customize things. Fully updated answerSeeing the excellent solution by jVincent below, I thought I should re-write eveything again to make this easier and more directed answer. To obtain the same display as one can with Matlab, follow these 2 simple steps
and Each time you want to disply a single With the above simple rule, now Mathematica will print the same thing as Matlab (and it looks even better since it uses
ps. I do not consider this as answer, since I using jVincent solution to show how to use it only. jVincent deserves the credit for this. |
|||||||||||
|
|
The reason why you get that output can be understood by looking at how Mathematica deals with matrices and what the A matrix is a list of listsA Using A simple list is neither a row nor a columnA simple list is just a collection of elements and cannot be transposed like a row/column. Indeed, you can see for yourself that it does not have a second singleton dimension which is necessary for a row/column vector.
(Note: these apply to ragged lists too, but I'll not address that here.) Contrast this with the behaviour for a row/column vector:
You can see that these have the second dimension and can be transposed back and forth. However, you can: Use
|
{x1,..,x5}and that by default is displayed as a column, you can put braces around it if you wish to display it as a row{cdsSpread5yrs[[2]]}//MatrixFormorcdsSpread5yrs[[{2}]]//MatrixForm– ssch Dec 19 '12 at 15:45MatrixForm[a[[1]], TableDirections -> Row]here is a screen shot: !Mathematica graphics (it is always a good idea to read help first) – Nasser Dec 19 '12 at 15:45