Copying the content of a Figure to another Figure

조회 수: 245 (최근 30일)
HA
HA 2019년 2월 12일
댓글: Walter Roberson 2019년 2월 14일
Hi,
I am trying to copy the directivity pattern of an antenna array from the figure generated by the pattern command to another window but so far did not manage to do that.
I am using copyobj command but it does not work. Here is the code that I am executing to achieve this goal:
fc = 60.48e9; % Carrier Frequency in Hz.
numElements = 16; % Number of antenna elements.
prop = physconst('LightSpeed');
lambda = prop/fc;
% ULA Antenne Array Creation.
array = phased.ULA(numElements, lambda/2);
f1 = figure();
pattern(array, fc, -180:180, 0, 'PropagationSpeed',prop,...
'CoordinateSystem', 'polar',...
'Type', 'powerdb', 'Normalize', true);
ax1 = gca;
f2 = figure();
ax = axes;
ax2 = copyobj(ax1,ax);
I am doing that because I did not manage to find a way to solve the problem listed in this Question. Using the method above, I will copy the content of the figure to a polaraxes in UIFigure in Matlab App Designer.
Any solution to one of the mentioned problems is highly appreciated.
  댓글 수: 4
HA
HA 2019년 2월 12일
@Jan, I think the question is clear. The code above is not doing what it should do i.e. copying the content of one figure to another.
Adam Danz
Adam Danz 2019년 2월 12일
But Jan wants to know what you mean by "it does not work". For example, are you getting an error message or a warning message? Is the image appearing but with missing objects? Does the code freeze? This type of clarity gives us a starting point to come up with ideas for a solution. Once I ran the code myself, seeing the error message immediately guided me to the solution. Since you didn't inlude an error message, Jan rightfully asked for clarity.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2019년 2월 12일
편집: Adam Danz 2019년 2월 13일
The function copyobj(h,p) copies objects listed in h to a new parent, p. When your code is run, the error message indicates, "Axes cannot be a child of Axes." This is because you cannot assign one axis as a child to another axis. Rather, you should copy the axis to a new figure.
Here's the correct way to do that:
f2 = figure();
ax2 = copyobj(ax1,f2);
[UPDATE]
To copy objects from one set of axes to another, you must first get handles to all of the axis children and then copy that list of handles to an existing axis. Here's a demo that follows the code in your question.
% Get handles for all children from ax1
ax1Chil = ax1.Children;
% Copy all ax1 objects to axis 2
copyobj(ax1Chil, ax2)
In your case, even though the axes you're copying from are polar axes, the data are actually plotted in Cartesian coordinates. So you'll copy the objects to a cartesian plot (middle figure below).
ax1Chil = ax1.Children;
figure;
ax2 = axes;
copyobj(ax1Chil, ax2)
axis equal
rectangle('Position', [-50 -50, 100, 100], 'Curvature', [1,1]) %Example: add circle
If you add the object to a polar axis, the (x,y) coordinates create a completely different pattern (right figure below).
ax1Chil = ax1.Children;
figure;
ax2 = polaraxes('ThetaTick', -150:30:180, 'ThetaLim', [-180, 180]);
copyobj(ax1Chil, ax2)
The image below shows [original, Cartesian axes, polar axes].
190213 095532-Figure 4.jpg
  댓글 수: 8
Adam Danz
Adam Danz 2019년 2월 14일
편집: Adam Danz 2019년 2월 14일
Interestingly, when I plot the (x,y) coordinates from the original plot onto a polar plot, it's just as distorted as when polaraxes() is used.
figure;
ax1Chil = ax1.Children;
ax2 = polar(ax1Chil.XData, ax1Chil.YData);
190214 090031-Figure 2.jpg
Walter Roberson
Walter Roberson 2019년 2월 14일
right because it is cartesian data , the polar plot converted to cartesian already .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by