How do I add/create an interactive 3D plot on a MATLAB GUI?

I try to embed an existing 3D plot on a separate GUI based on the example shown below:
I follow the procedure of manually implementing a GUI (aka not using MATLAB GUIDE) for which I want the 3D plot to be an (interactive) part of it (like a pushbutton). However, I have no clue how to add the pre-existing figure of the shown example to it, or how I would make use of the function copyobj correctly, assuming it's needed.

 採用された回答

Luna
Luna 2019 年 1 月 9 日
編集済み: Luna 2019 年 1 月 9 日

0 投票

Hi Joshua,
You can try below code:
You should create a panel, or an axes in some position and then add your plot to that container.
hFig = figure;
hAxes = axes('Parent',hFig);
x = 0:10;
y = 0:2:20;
z = rand(size(x,2),size(y,2));
hPlot = surf(hAxes,x,y,z);
hPlot.FaceAlpha = 0.7;
hPlot.EdgeAlpha = 0.3;
hPlot.FaceColor = 'interp';
hPlot.EdgeColor = [0 0 0];
hPlot.EdgeLighting = 'gouraud';
% you can change any other color or edge properties as you wish
rotate3d on;

3 件のコメント

Joshua
Joshua 2019 年 1 月 9 日
Hi Luna,
thanks for your answer. However, my issue is another one (I described it quite vaguely, which could have led to a misunderstanding here). I will try to clarify it:
The GUI and the 3D plot (actually more like 3-dimensional axes with different surfaces in it, like the video I linked above, aka not using the surf function), are 2 separated figures right now.
In my GUI (function), I put separate GUI elements into a structure, like the following:
% example code
strct.fighandle = figure('properties etc.');
strct.btn(btn_idx) = uicontrol('properties etc.');
etc.
In the other function, in which I currently have my 3d surface model, I basically define the axis, which creates a different figure, then I put different surfaces on it with the surface function like:
% example code
axis_handle = axes('XLim, YLim and ZLim properties');
view(3);
%....
sf_handle(sf_idx) = surface('coordinates & properties');
set(sf_handle(sf_idx), 'Parent', axis_handle);
Now I want to add the content of that figure (aka the 3D plot including the surfaces) onto my GUI like another UI object I could set the coordinates of; just like a panel or button.
Adam
Adam 2019 年 1 月 9 日
Why can you not just add it to your GUI in the first place instead of on a seperate figure?
Luna
Luna 2019 年 1 月 9 日
編集済み: Luna 2019 年 1 月 9 日
As I told above create your axis inside the figure using parent property:
You should define your strct under the handles so you can reach them from another function.
axis_handle = axes('Parent',strct.fighandle,'Position',[x,y,width,height],'XLim, YLim and ZLim properties');
sf_handle(sf_idx) = surface('coordinates & properties');
surf and surface functions both can have the axes handle in the first input and returns the surface object.
rotate3d on should work in both cases.
rotate3d on
Or share the entire code so that we can fix.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

質問済み:

2019 年 1 月 9 日

編集済み:

2019 年 1 月 9 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by