problem with name=value syntax

6 visualizaciones (últimos 30 días)
Matt Fetterman
Matt Fetterman el 10 de Mayo de 2021
Comentada: xingxingcui el 30 de Jul. de 2021
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 comentario
xingxingcui
xingxingcui el 30 de Jul. de 2021
I think the way you wrote the call should be supported!there is no doubt in python and C++ languages

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 10 de Mayo de 2021
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 comentarios
Steven Lord
Steven Lord el 10 de Mayo de 2021
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 el 30 de Jul. de 2021
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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by