the release notes for R2021a have name=value syntax.
I try it but it isn't working for me.
Error using experimental.mfetterman.MonteCarloStudy.testFunc>calcJ
Too many input arguments.
Error in experimental.mfetterman.MonteCarloStudy.testFunc (line 3)
calcJ(A=ark,B=bark);
ark=randn(5,3);
bark=randn(6,2);
calcJ(A=ark,B=bark);
function calcJ(A,B)
fprintf('rank A:%d\n',rank(A));
fprintf('rank B:%d\n',rank(B));
end

댓글 수: 1

xingxingcui
xingxingcui 2021년 7월 30일
I think the way you wrote the call should be supported!there is no doubt in python and C++ languages

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

 채택된 답변

Steven Lord
Steven Lord 2021년 5월 10일

2 개 추천

That syntax is intended as a way to specify name-value pair arguments. So instead of:
plot(1:10, 1:10, 'Marker', 'o', 'LineStyle', ':')
you could write:
plot(1:10, 1:10, Marker = 'o', LineStyle = ':')
Your example does not use name-value pair arguments at all. What you wrote is:
calcJ(A=ark,B=bark); % equivalent to
calcJ('A', ark, 'B', bark);
Your calcJ function does not accept four inputs. It accepts two.

댓글 수: 3

Matt Fetterman
Matt Fetterman 2021년 5월 10일
OK thanks is there a "right" way to do it like I wanted.
Either get rid of the names in your call:
ark=randn(5,3);
bark=randn(6,2);
calcJ(ark,bark);
function calcJ(A,B)
or modify your function so it accepts name-value pairs. The arguments keyword or inputParser will help you if you choose this approach.
xingxingcui
xingxingcui 2021년 7월 30일
Is it possible to enhance the new syntax "Name=Value Syntax" introduced in version R2021a?
It would be nice to have enhancements in future versions!

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2021년 5월 10일

댓글:

2021년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by