Adding a “hold” after a “number” causes the chart to be different

I have three 5x5 matrices, i.e. X , Y and U Here is how they look.

 X = 0 0 0 0 0 0.2500 0.2500 0.2500 0.2500 0.2500 0.5000 0.5000 0.5000 0.5000 0.5000 0.7500 0.7500 0.7500 0.7500 0.7500 1.0000 1.0000 1.0000 1.0000 1.0000 Y = 0 0.2500 0.5000 0.7500 1.0000 0 0.2500 0.5000 0.7500 1.0000 0 0.2500 0.5000 0.7500 1.0000 0 0.2500 0.5000 0.7500 1.0000 0 0.2500 0.5000 0.7500 1.0000 U = 0 0.2474 0.4794 0.6816 0.8415 0.3093 0.5991 0.8519 1.0519 1.1862 0.7191 1.0224 1.2623 1.4238 1.4962 1.1929 1.4727 1.6611 1.7460 1.7220 1.6829 1.8980 1.9950 1.9680 1.8186 

Now, if I try to build U using the following snippet:

 figure; mesh(X, Y, U); 

This is the conclusion:

enter image description here

If instead I use the following code:

 figure; hold on; mesh(X, Y, U); 

I get:

enter image description here

Why is this happening? Apparently, without hold on , I have another dimension. I do not know for what reason this will be correct. Why does Matlab do this?

+6
source share
1 answer

To understand what is happening, it is important to know that for most MATLAB build commands, unless axes explicitly specified in the command, the current axes used by default. If no axes exists, one is created and its appearance is completely controlled by the charting team. If the current axes object exists, usually the plot command will not change the appearance of the axes object, since in theory you already configured it.

hold on changes the NexPlot property for the current axes so that the next object that has been drawn does not overwrite previous objects. If axes does not currently exist, hold will implicitly create the axes object. The default view for this new axis object is a 2D XY view. Since the axes object now already exists when you call mesh , it just uses the current view (and other axes parameters), rather than changing it.

In case you don't call hold on , there are no axes before calling mesh , so mesh creates an axes object on its own with properties that are ideal for rendering the mesh. This includes using a three-dimensional view and displaying grid lines.

You can manually change the axes properties created by hold on by calling view(3) to use the default 3D view and grid on to enable grid labels

 figure hold on % Make it the default 3D view view(3) % Show the gridlines grid on mesh(X, Y, U) 
+7
source

Source: https://habr.com/ru/post/1012382/


All Articles