gca function in matlab

I have read the matlab docs but I don't understand what gca really does. Can somebody explain it to me? Thanks!

 采纳的回答

Iain
Iain 2014-8-20

1 个投票

gca returns the handle to the current axis. - it generates one if there is no current axis.

4 个评论

With "handle to the current axis" do you mean the scale of the axis?
No, a handle is a number which refers to an object. Object can be axes, figure, lines, whatever. If you want to do something with an object (change properties or get values of properties), you need to refer to this object. That's done by the handle. e.g:
get(gca,'xlim')
will give you the limits of the x axes of the current axes.
set(gca,'ylim',[-100 100])
will set the ylimits to +-100.
Michael, thanks for the answer! it's clear now :)
I use the command to plot matlab figure. I also use the code
set (gca)
d=axes('position',get(gca,'position'),'visible','off');
but there are so many things comes in command window. I afraid with these. Are these any problem in plotting the matlab figure?
These are
ALim: {}
ALimMode: {'auto' 'manual'}
ActivePositionProperty: {1×2 cell}
AmbientLightColor: {1×0 cell}
Box: {'on' 'off'}
BoxStyle: {'full' 'back'}
BusyAction: {1×2 cell}
ButtonDownFcn: {}
CLim: {}
CLimMode: {'auto' 'manual'}
CameraPosition: {}
CameraPositionMode: {'auto' 'manual'}
CameraTarget: {}
CameraTargetMode: {'auto' 'manual'}
CameraUpVector: {}
CameraUpVectorMode: {'auto' 'manual'}
CameraViewAngle: {}
CameraViewAngleMode: {'auto' 'manual'}
Children: {}
Clipping: {'on' 'off'}
ClippingStyle: {1×2 cell}
Color: {1×0 cell}
ColorOrder: {}
ColorOrderIndex: {}
CreateFcn: {}
DataAspectRatio: {}
DataAspectRatioMode: {'auto' 'manual'}
DeleteFcn: {}
FontAngle: {1×2 cell}
FontName: {}
FontSize: {}
FontSmoothing: {'on' 'off'}
FontUnits: {1×5 cell}
FontWeight: {'normal' 'bold'}
GridAlpha: {}
GridAlphaMode: {'auto' 'manual'}
GridColor: {1×0 cell}
GridColorMode: {'auto' 'manual'}
GridLineStyle: {1×5 cell}
HandleVisibility: {1×3 cell}
HitTest: {'on' 'off'}
Interruptible: {'on' 'off'}
LabelFontSizeMultiplier: {}
Layer: {'bottom' 'top'}
LineStyleOrder: {}
LineStyleOrderIndex: {}
LineWidth: {}
MinorGridAlpha: {}
MinorGridAlphaMode: {'auto' 'manual'}
MinorGridColor: {1×0 cell}
MinorGridColorMode: {'auto' 'manual'}
MinorGridLineStyle: {1×5 cell}
NextPlot: {1×4 cell}
OuterPosition: {}
Parent: {}
PickableParts: {1×3 cell}
PlotBoxAspectRatio: {}
PlotBoxAspectRatioMode: {'auto' 'manual'}
Position: {}
Projection: {1×2 cell}
Selected: {'on' 'off'}
SelectionHighlight: {'on' 'off'}
SortMethod: {1×2 cell}
Tag: {}
TickDir: {1×3 cell}
TickDirMode: {'auto' 'manual'}
TickLabelInterpreter: {1×3 cell}
TickLength: {}
Title: {}
TitleFontSizeMultiplier: {}
TitleFontWeight: {'normal' 'bold'}
UIContextMenu: {}
Units: {1×6 cell}
UserData: {}
View: {}
Visible: {'on' 'off'}
XAxis: {}
XAxisLocation: {1×3 cell}
XColor: {1×0 cell}
XColorMode: {'auto' 'manual'}
XDir: {1×2 cell}
XGrid: {'on' 'off'}
XLabel: {}
XLim: {}
XLimMode: {'auto' 'manual'}
XMinorGrid: {'on' 'off'}
XMinorTick: {'on' 'off'}
XScale: {'linear' 'log'}
XTick: {}
XTickLabel: {}
XTickLabelMode: {'auto' 'manual'}
XTickLabelRotation: {}
XTickMode: {'auto' 'manual'}
YAxisLocation: {1×3 cell}
YColor: {1×0 cell}
YColorMode: {'auto' 'manual'}
YDir: {1×2 cell}
YGrid: {'on' 'off'}
YLabel: {}
YLim: {}
YLimMode: {'auto' 'manual'}
YMinorGrid: {'on' 'off'}
YMinorTick: {'on' 'off'}
YScale: {'linear' 'log'}
YTick: {}
YTickLabel: {}
YTickLabelMode: {'auto' 'manual'}
YTickLabelRotation: {}
YTickMode: {'auto' 'manual'}
ZAxis: {}
ZColor: {1×0 cell}
ZColorMode: {'auto' 'manual'}
ZDir: {1×2 cell}
ZGrid: {'on' 'off'}
ZLabel: {}
ZLim: {}
ZLimMode: {'auto' 'manual'}
ZMinorGrid: {'on' 'off'}
ZMinorTick: {'on' 'off'}
ZScale: {'linear' 'log'}
ZTick: {}
ZTickLabel: {}
ZTickLabelMode: {'auto' 'manual'}
ZTickLabelRotation: {}
ZTickMode: {'auto' 'manual'}
>> my code to plot the matlab figure given below as: if (Ps==Ps1(1)) yyaxis left T1=semilogy(Bi,sop_si,'*'); grid on;hold on; T2=semilogy(Bi,sop_th,'-'); grid on;hold on; xlabel('Power Splitting Factor for Energy Harvesting, (\beta)'); ylabel('Secrecy Outage Probablity');
yyaxis right
T3=semilogy(Bi,p_out_si,'>');
grid on;hold on;
T4=semilogy(Bi,p_out_th,'-');
grid on;hold on;
ylabel('Harvested Power Outage Probability')
else
yyaxis left
D1=semilogy(Bi,sop_si,'*');
grid on;hold on;
D2=semilogy(Bi,sop_th,'-');
grid on;hold on;
yyaxis right
D3=semilogy(Bi,p_out_si,'>');
grid on;hold on;
D4=semilogy(Bi,p_out_th,'-');
grid on;hold on;
d=axes('position',get(gca,'position'),'visible','off');
legend([T1 T2 D1 D2],'Simulation, P_S=5 dBW, SOP', 'Analytical, P_S=5 dBW, SOP','Simulation, P_S=10 dBW, SOP', 'Analytical, P_S=10 dBW, SOP','Location','NorthEastoutside');
legend(d,[T3 T4 D3 D4],'Simulation, P_S=5 dBW, HPOP', 'Analytical, P_S=5 dBW, HPOP','Simulation, P_S=10 dBW, HPOP', 'Analytical, P_S=10 dBW, HPOP','Location','EastOutside');

请先登录,再进行评论。

更多回答(1 个)

Hi Civs,
To my knowledge whenever an object is created (figure, window, axes, function,...) a handle is associates to the object it's like when you want do define a number value, you assign it to a variable,
a = 2;
when you create a figure, axes and ... you can assign them to a variable(handle)
h = figure()
I = axes()
so when you want to plot on a specific axes, let's say you have 10 figures and axes open, and you want to plot on an axes you previously names regression
regression = axes(); % this creates an axes and name it regression
plot(regression,x,y); % this plots on the axes named regression not the other ones
to find which axis is currently viewing or which one is recently clicked (viewed), or more programmatically speaking has the focus, you can use gca which gives you the handle(assume it as variable) to the current figure.
read more about handles it's useful.

类别

帮助中心File Exchange 中查找有关 Graphics Object Properties 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by