Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control the display of a double matrix in MATLAB?

How can I change the format to NOT display a matrix like this:

 1.0e+003 *

3.1251         0         0         0         0         0         0         0         0         0
     0    3.1251         0         0         0         0         0         0         0         0
     0         0    3.1251         0         0         0         0         0         0         0
     0         0         0    3.1251         0         0         0         0         0         0
     0         0         0         0    3.1251         0         0         0         0         0
     0         0         0         0         0    3.1251         0         0         0         0
     0         0         0         0         0         0    3.1251         0         0         0
     0         0         0         0         0         0         0    3.1251         0         0
     0         0         0         0         0         0         0         0    3.1251         0
     0         0         0         0         0         0         0         0         0    3.1251

but instead to include the 1.0e+003 into every double so that the matrix looks like 3125 along the diagonal?

like image 803
tim Avatar asked May 09 '11 17:05

tim


People also ask

How do you display a matrix element in MATLAB?

Indexing with Element Positions For example, to access a single element of a matrix, specify the row number followed by the column number of the element. e is the element in the 3,2 position (third row, second column) of A . You can also reference multiple elements at a time by specifying their indices in a vector.

How do you display two variables in MATLAB?

Display Multiple Variables on Same Line Here are three ways to display multiple variable values on the same line in the Command Window. Concatenate multiple character vectors together using the [] operator. Convert any numeric values to characters using the num2str function. Use disp to display the result.

How do you change the precision of a screen in MATLAB?

Select MATLAB > Command Window, and then choose a Numeric format option. See the format reference page for a list and description of all supported numeric formats.


1 Answers

You can get the output you want if you change the format to shortG (based on Example 5 of the documentation):

>> format shortG
>> 3125.1234.*eye(5)   %# Display a sample matrix similar to yours

ans =

       3125.1            0            0            0            0
            0       3125.1            0            0            0
            0            0       3125.1            0            0
            0            0            0       3125.1            0
            0            0            0            0       3125.1
like image 200
gnovice Avatar answered Oct 07 '22 00:10

gnovice