MATLAB For Dummies
Book image
Explore Book Buy On Amazon

How the 3D effect appears onscreen depends on the data aspect ratio you set in MATLAB. The daspect() function lets you obtain the current aspect ratio and set a new one. The aspect ratio is a measure of how the x-, y-, and z-axis interact.

For example, an aspect ratio of [1, 2, 3] would mean that for every 1 unit of the x-axis, there are two units of the y-axis and three units of the z-axis. Perform the following steps to see how this feature works:

Type YSource = [1, 3, 5; 3, 7, 9; 5, 7, 11]; and press Enter.

MATLAB creates a data source for you.

Type Bar1 = bar3(YSource); and press Enter.

You see a 3D bar chart appear.

Type rotate(Bar1, [0, 0, 1], 270); and press Enter.

Type rotate(Bar1, [0, 0, 1], 270); and press Enter.

The bar chart rotates so that you can see the individual bars easier.

Type daspect() and press Enter.

The output contains three values, like this:

ans =
 0.3571 0.2679 2.1670

So, you now know the current aspect ratio of the plot, with the first number representing the x-axis value, the second number the y-axis value, and the third number the z-axis value.

Type daspect([.25, 1, 1.2]); and press Enter.

Type daspect([.25, 1, 1.2]); and press Enter.

The data aspect ratio changes to create tall, skinny-looking bars. The data is precisely the same as before, as is the rotation, but the interpretation of the data changes.

Type daspect([.65, .5, 7]); and press Enter.

Type daspect([.65, .5, 7]); and press Enter.

The impression is now that the differences between the data points are actually quite small. Again, nothing has changed in the data or the rotation. The only thing that has changed is how the data is presented.

Type daspect(‘auto’) and press Enter.

The data aspect returns to its original state.

About This Article

This article is from the book:

About the book authors:

John Paul Mueller is an author and technical editor with experience in application development, database management, machine learning, and deep learning. He has written hundreds of books and articles helping everyday people learn everything from networking to database management.

John Mueller has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services (AWS). Luca Massaron, a Google Developer Expert (GDE),??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques.

This article can be found in the category: