Here, we will review how numbers imported from an Excel workbook are displayed when they are either very large or have fractional parts. If you are either unaware or forgetful of how MATLAB decides to display various types of numeric values by default, you might come to an erroneous conclusion about the nature of the data imported. from an Excel workbook. With this in mind, we're going to do a quick review of default display modes in MATLAB to remind you to be careful when trying to interpret values read from an Excel spreadsheet and displayed using the default MATLAB display modes.
In most circumstances, the programmer will control the method of displaying various numeric values within the program. However, very often during program development and debugging, you may allow MATLAB simply to dump information to the screen in its default mode so that you don't have to spend the time developing more clearly formatted output modes. Once again, we will be using the workbook, demo workbook, So please make sure that file is on your current path. As we have seen numerous times already, when we have imported a group of values containing only moderately small integers, they are simply displayed as integers.
For example, let's consider the sheet demo1. In this case, it's very difficult to misinterpret. the data that you see within that matrix.
However, when the data being displayed contains values that are very large or fractional, and particularly if the values range over several orders of magnitude, you need to be careful in interpreting what you see on the screen when using the default display mode. Let's begin by considering the import of numeric data. containing only values with a magnitude less than a thousand, some of which are fractional, and none of which are less than about 1 one-hundredth. Sheet Demo 10 contains such a dataset. Note that all of these values, both integer and fractional, are displayed using a default format of four decimal places with up two three digits to the left of the decimal point.
This is also fairly clear and unlikely to be seriously misinterpreted. However, the integers may look a little funny due to the zeros trailing behind the decimal point. The only thing of any note here is that if the fractional part of the number requires more than four significant figures to display.
It will be rounded to four significant figures, so there may be other numeric information off to the right of the actual displayed values. This is usually not a problem. Next, let's consider a case in which there are fairly small values to be imported as in sheet demo 11. Note here that the value from cell B1 is displayed as .0001.
1, which could be a little misleading if you don't remember that there may be more digits to the right of what is actually displayed. The value imported from B3, however, is a little more problematic because it certainly appears to be 0, which we know to be not true. The 3 in the fifth decimal place is indeed stored in the variable.
But when it's displayed in the default mode, it's simply rounded to zero. The computer will not get confused by this, but we humans can easily mistake this for exactly zero. You can always display just a single value from a matrix, in which case MATLAB will display that in a mode more appropriate for that one specific value. So that... lower right value that appears to be zero is actually shown to be three times ten to the minus fifth we could use this same method to take a closer look at the upper Right value, the one that simply says .0001 to see if there are further significant figures to the right of the 1. And indeed we see that the 1 actually wasn't even there.
It was a 7. in the fifth place that was rounded up to a one. Note that in both of these cases, MATLAB switched to a scientific format with five significant figures and an exponent. Now, Let's complicate the issue even further by adding a value with a magnitude greater than 1,000, as in sheet demo 12. Remember that previously, when we had fractional values, the default display mode was up to three digits to the left of the decimal point plus four decimal places.
If the integer part of the value is 1,000 or greater, however, three digits is in the insufficient to display the integer part. And so MATLAB automatically factors out a common power of 10 from all of the values, displays that power of 10 at the top, and then displays the rest of the values below that. It's up to you to remember that every single one of those values has to be multiplied by the shown power of 10 at the top.
This is fairly easy. easy to forget particularly if you have a fairly large matrix with lots of values that common power of 10 at the top is easy to get lost the common power of 10 is determined based on the value with the largest magnitude and is chosen so that that value will have a single nonzero digit to the left of the decimal point. So in this case, the value 8,735 dictates that a power of 1,000, 10 to the third, is factored out of all the values and And that value is displayed as 8.7350, of course, times that common power of 10. Note that any values in the matrix that have a magnitude less than the common power of 10 will be displayed with a 0 to the left of the decimal place. And depending on their magnitude, if they're fairly small, the first significant digit may be... to the right of the display digits, and it will simply appear as zero.
Thus, again, caution is warranted. Let's return for a moment to sheets containing only integers, as shown in sheet demo 13. In this case, however, we have a couple of values with fairly large magnitudes. Let's see how these are displayed.
Note that the default display aligns each column at a tab stop on the right. This sets an upper limit of how large an integer can be displayed considering both the significant figures and any possible sign on the left. If the two numbers in the second column get much larger, there's not going to be enough space to display all of the digits without bubbling. bumping up against the numbers in the first column, which would certainly be confusing. And MATLAB's not going to allow that to happen.
It's got to leave a space between the two columns. So let's increase the size of those two large integers just a little bit in order to see what MATLAB does when this situation occurs. Sheet demo 14 has this modification.
When at least one of the values... exceeds a magnitude of 1 billion, 10 to the 9th, MATLAB has to switch to scientific notation in order to display that value. And just as we saw before, it factors a common power of 10 out of all of the values. That means that for this data set, we've actually got half of our values that appear to be zero, which again, we know not to be the case.
In addition, the second value in the first column simply has a single significant figure of one where there may be more to the right that we cannot see. Again, you can display the individual values and MATLAB will display these with a more appropriate format. So we see that the middle value in the second column is actually 35, not 0. And we could look at the others as well to see what they are in actuality.
To summarize, the major pitfalls we have discussed are the fact that when MATLAB, by default, switches to scientific display mode, you must remember to look for an overall power of 10 at the top, but which... all of the values must be multiplied many of the values may not have all of their significant figures displayed and in particular values displayed as zero may have significant figures off to the right that simply don't show up at all at this point we have pretty much beaten read matrix to death so we will move on to write matrix complementary function that allows you to write numeric data into an Excel work