Re-use the view output matrix in Matlab

浪尽此生 提交于 2019-12-02 04:01:58

问题


In Matlab, I create a fairly complicated 3D plot, then manipulate the view option by hand up to a point where I am happy with what I see (below). How can I reuse the parameters of the final view? I can get the output of the view command which is a 4 by 4 matrix, but the latter does not seem to be reusable?


回答1:


In order to get something out of view that you can then pass to view to reconstruct the viewpoint, you need to specify two outputs to view which will yield the current azimuth and elevation.

[az, el] = view(ax1);

You can then pass these to view on a different (or the same) axes to specify the viewpoint

view(ax2, az, el);

You can also use the View property of the axes object.

AzEl = get(ax1, 'View');
set(ax2, 'View', AzEl);

Note, however, that there are many properties which control the view of an axes including the Projection, the DataAspectRatio, the PlotBoxAspectRatio and all of the camera properties. Depending on your use case, you may need to specify these as well.




回答2:


ok, based on Suever's comments, I realized that all the figure properties I need can be accessed through the Graphical Interface called matlab.graphics.axis.Axes. This is where the parameters of the camera can be found. Another approach is to find them one by one as follows:

get(gca,'Projection')
get(gca,'CameraPosition')
get(gca,'CameraViewAngle')
get(gca,'CameraTarget')

and then set them directly in the script:

set(gca,'Projection','perspective')
set(gca,'CameraPosition',[-7 -5 3]/15)
set(gca,'CameraViewAngle',85)
set(gca,'CameraTarget',[0 .5 0])

I originally thought the view command would provide this information at once.



来源:https://stackoverflow.com/questions/36782582/re-use-the-view-output-matrix-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!