Style in Matlab functions

조회 수: 3 (최근 30일)
Stefan Martinek
Stefan Martinek 2023년 2월 8일
답변: Jan 2023년 2월 8일
What style is preferred in function variables? E.g.:
figure('WindowState','maximized') vs. figure('windowstate','maximized') vs. figure('WindowState','Maximized'); or find(xxx,1,'first') vs. find(xxx,1,'First') etc.
All the above works, but is any version more robust towards future Matalb updates?
Thank you.
Stefan
  댓글 수: 1
Vilém Frynta
Vilém Frynta 2023년 2월 8일
I don't think that this will change in future updates, however, I think you can't go wrong with the styles that are used in the official documentations.
On the figure documentation website, there are some code examples:
figure('Name','Measured Data','NumberTitle','off');
set(groot,'DefaultFigureColormap','remove')
Theses examples look just like yours figure('WindowState','maximized').
Arguments have big letter at the end of each word and their values are lowercased (unless it's your own value like name).
However, I am not Mathworks employee and I do not have any information on this topic. This is something that just makes the most sense to me.

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

답변 (1개)

Jan
Jan 2023년 2월 8일
I use the upper/lower case of the default setting:
h = figure;
set(h)
Alphamap: {} BusyAction: {'queue' 'cancel'} ButtonDownFcn: {} Children: {} Clipping: {[on] [off]} CloseRequestFcn: {} Color: {1×0 cell} Colormap: {} ContextMenu: {} CreateFcn: {} CurrentAxes: {} CurrentCharacter: {} CurrentObject: {} CurrentPoint: {} DeleteFcn: {} DockControls: {[on] [off]} FileName: {} GraphicsSmoothing: {[on] [off]} HandleVisibility: {'on' 'callback' 'off'} Icon: {} InnerPosition: {} IntegerHandle: {[on] [off]} Interruptible: {[on] [off]} InvertHardcopy: {[on] [off]} KeyPressFcn: {} KeyReleaseFcn: {} MenuBar: {'none' 'figure'} Name: {} NextPlot: {'new' 'add' 'replace' 'replacechildren'} NumberTitle: {[on] [off]} OuterPosition: {} PaperOrientation: {'portrait' 'landscape' 'rotated'} PaperPosition: {} PaperPositionMode: {'auto' 'manual'} PaperSize: {} PaperType: {1×26 cell} PaperUnits: {'inches' 'centimeters' 'normalized' 'points'} Parent: {} Pointer: {'arrow' 'ibeam' 'crosshair' 'watch' 'topl' 'topr' 'botl' 'botr' 'circle' 'cross' 'fleur' 'custom' 'left' 'top' 'right' 'bottom' 'hand'} PointerShapeCData: {} PointerShapeHotSpot: {} Position: {} Renderer: {'painters' 'opengl'} RendererMode: {'auto' 'manual'} Resize: {[on] [off]} Scrollable: {[on] [off]} SelectionType: {'normal' 'open' 'extend' 'alt'} SizeChangedFcn: {} Tag: {} ToolBar: {'none' 'auto' 'figure'} Units: {'inches' 'centimeters' 'characters' 'normalized' 'points' 'pixels'} UserData: {} Visible: {[on] [off]} WindowButtonDownFcn: {} WindowButtonMotionFcn: {} WindowButtonUpFcn: {} WindowKeyPressFcn: {} WindowKeyReleaseFcn: {} WindowScrollWheelFcn: {} WindowState: {'normal' 'maximized' 'minimized' 'fullscreen'} WindowStyle: {'normal' 'modal' 'docked' 'alwaysontop'}
The documentation explains, that the names and values are not case-sensitive, so it can be expected to be compatible with future versions also. Matlab is very stable in such documented details.
Using the dot notation requires the correct case for the names:
h.WindowState = 'normal';
% Error:
h.windowstate = 'normal';
Unrecognized property 'windowstate' for class 'matlab.ui.Figure'.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by