how to get matrix value right?
1 view (last 30 days)
Show older comments
i am working on transferring some values to a matrix from another one. when i am printing the results individually like new(1,1) its showing exact result, but when printing whole new its giving totally wrong answer with (1.0e+003 *) on above.how to solve the problem?
new(row,col)=newMatrix(l,k,m); disp(new(1,1));-gives right answer but- disp(new); gives all wrong.
0 Comments
Accepted Answer
Stephen23
on 15 Aug 2015
Edited: Stephen23
on 17 Aug 2015
Actually MATLAB is displaying the correct values, but they are simply being displayed using scientific notation. Scientific notation is a very common convenient way to write large/small numbers, without using lots of digits. Lets have a look at some simple examples:
>> 1000000000 % one with nine zeros
ans =
1.0000e+09
>> 1e9 % easier to input it like this
ans =
1.0000e+09
And if the values are in an array, then a common exponent is placed above the displayed values (it becomes a factor of all of the values displayed in the array below it):
>> [1e9,2e10]
ans =
1.0e+10 *
0.1000 2.0000
This is the correct behavior, not an error. You can find more information about scientific format on the the internet. If you want to change how the values are displayed, then have a look at format, and try some of the options until you find one that you like:
>> format longG
>> [1e9,2e10]
ans =
1000000000 20000000000
Note that the docs suggest that shortG might be suitable for data that has a wide range of values.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!