对参数-值输入对使用缩写-为什么cellfun的''UniformOutput',false'用作''un',0'? [英] Using abbreviations for parameter-value input pairs - why does cellfun's `'UniformOutput', false` work as `'un', 0`?

查看:390
本文介绍了对参数-值输入对使用缩写-为什么cellfun的''UniformOutput',false'用作''un',0'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为cellfun(..., 'UniformOutput', false)的经常使用者,我惊讶地发现后两个参数可以输入为cellfun(..., 'un', 0).这立即缩短了我的代码.我的问题是,那里还有其他类似的快捷方式/别名吗?

As a frequent user of cellfun(..., 'UniformOutput', false), I was surprised to discover that the latter two arguments could be input as cellfun(..., 'un', 0). This has immediately shortened my code. My question is, are there any another similar shortcuts/aliases out there?

这似乎未在MathWorks网站上记录.调皮!

This doesn't appear to be documented on the MathWorks website. Naughty!

推荐答案

背景

通常可以将属性-值"对的属性"部分缩短到属性字符串的开头,只要它仍然是唯一可识别的即可(请参见下面的示例).它们通常也不区分大小写.
据我所知,除了图形属性以外,没有任何文档记录,其中

Background

The property part of a Property-value pair can be often be shortened to the beginning of the property string so long as it is still uniquely identifiable (see examples below). They are also often not case sensitive.
As far as I know this is not documented for anything other than figure properties, where it is very briefly documented.

但是,在许多带有属性-值对参数的MathWorks函数中以及在某些不带值对的字符串参数的函数中,也都实现了这种行为.

However this behaviour is also implemented in many The MathWorks functions which take property-value pair arguments, and also in some functions which take string arguments with no value pair.

问题就变成了其他属性...

The problems become what other properties are there...

  • 对于某些功能,没有很好的文档说明...(很多都是 内置或混淆的.p文件,因此无需检查源代码).
  • 最重要的是,我们不知道将来的版本是否会引入新的 属性.
  • For some functions is not well documented... (and many are either built-in or obfuscated .p files, so no checking the source).
  • Most importantly we cannot know if future versions will introduce new properties.

出于这个原因,建议不要使用缩写的属性名称

如果缩写名称由于添加了新属性而不再唯一,则使用完整属性名称可以防止MATLAB未来版本出现问题." - Matlab文档

"不要用P-V缩写来缩短代码,这不值得,相信我." – 萨姆·罗伯茨

简要的技术方面-Matlabs inputParser默认情况下实现了此功能,但是可以禁用,因此这些缩写不能保证在所有功能上均有效.仅以这种方式使用inputParser的人或专门为此目的编写的人.

The brief slightly technical side - This functionality is implemented by default by Matlabs inputParser, however it can be disabled so these abbreviations are by no means guaranteed to work on every function. Only those which use the inputParser in this way or are specifically written to allow this.

  1. 简单缩短

以下

hFig = figure();
get(Hfig,'Visible')
ans =

on

可以缩写为

hFig = figure();
get(Hfig,'v')
ans =

on

,因为它是唯一以'v'开头的属性(请注意,'vi''vis'等也可以使用)

as it is the only property beginning with 'v' (note that 'vi','vis', etc... also work)

  1. 唯一性

但是其他类似开始的属性,例如CurrentAxesCurrentCharacter& CurrentObject

However other properties which start similarly e.g. CurrentAxes, CurrentCharacter & CurrentObject

get(Hfig,'Current')

Error using get
Ambiguous property found.
Object Name: figure
Property Name: 'Current'.

'currenta''currentc''currento'是唯一可识别的,并且可以按预期工作

Where as 'currenta','currentc' and 'currento' are uniquely identifiable and would work as intended

  1. 不可能缩短

特别提及诸如ColorColorMap之类的属性,其中一个的名称是另一个的开头 Color只能与全名一起使用,因为ColorMap的任何缩写都含糊不清 可以像以前一样将'ColorMap'短接到'colorm'.

A special mention to properties such as Color and ColorMap the name of one is the beginning of another Color can only be used with its full name, due to any shortening being ambiguous with ColorMap 'ColorMap' can be shorted to 'colorm' however, as before.

本节旨在通过显示一些看似不可预测不可预测的行为,来劝阻使用缩短的财产价值对.

This section aims to discourage use of shortened property value pairs by showing some of the seemingly unpredictable and unexpected behaviour.

半未公开的hardcopy具有一些有趣的行为,该文件指出可能的选项为-dps,-deps,-dps2,-deps2,-dill和-dhpgl

The semi-undocumented hardcopy has some interesting behaviour the documentation states possible options as -dps,-deps,-dps2,-deps2,-dill,-dhpgl

但是'-dh'会产生一个错误,因为'-di'是缩写'-dill'的缩写,但遗憾的是,没有检查源以查看为什么它是.p文件

However '-dh' creates an error where as '-di' works as an abbreviated '-dill' sadly there is no checking the source to see why as it is a .p file

最后,cellfun本身并不完全遵循那里的规则,因为如果遵循上述规则,'u'在理论上应该可以工作,但是只有'un'及更高版本可以.

Finally cellfun itself doesn't exactly follow there rules as 'u' should theoretically work if following the rules above, however only 'un' and onwards does.

这篇关于对参数-值输入对使用缩写-为什么cellfun的''UniformOutput',false'用作''un',0'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆