逗号分隔或不返回MATLAB函数之间有什么区别? [英] What is the difference between comma separated or not MATLAB function return?
问题描述
我忘记了在MATLAB中某个函数的某些返回之间的逗号,并且它没有抱怨.
I forgot commas between some returns of a function in MATLAB and it did not complain.
function [returnA, returnB]=foo(paramA)
returnA=ones(1,10).*paramA;
returnB=magic(4);
end
function[]=voo()
%typing the return as this
[A,B]=foo(5);
%gives the same result as
[A B]=foo(5);
end
我的问题是:它是完全一样的行为吗?我在文档
My question is: is it exactly the same behavior? I was not able to find it in documentation
推荐答案
是的,行为与您在问题中提供的代码相同.
Yes, it is the same behavior, as seen with the code you provide in your question.
正如@LuisMendo在评论中指出的那样,如果您查看MATLAB的棉绒(又称代码分析器)消息在编辑器中,您将看到:
As @LuisMendo points out in the comments, if you look at the MATLAB's lint (aka Code Analyzer) message in the editor you'll see:
最佳做法是用逗号分隔输出变量
Best practice is to separate output variables with commas
这暗示着这两种语法都是有效的.至于为什么,我不确定这种情况,而且我找不到真正倾向于仅仅因为"的具体内容.正如@rayryeng在评论中指出的那样,它也可能与将语法与MATLAB的
Which implies that both syntaxes are valid. As to why this is the case I'm not sure, and I can't really find anything specific which tends to point towards "just because." As @rayryeng points out in the comments, it could also have to do with aligning syntax with MATLAB's comma-separated lists.
这篇关于逗号分隔或不返回MATLAB函数之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!