MATLAB Answers

Populate pyargs() arguments with the contents of a string cell array.

5 views (last 30 days)
Ajpaezm
Ajpaezm on 22 May 2018
Edited: Stephen Cobeldick on 22 May 2018
Hello everybody,
I'd like to know if there's a way to populate the arguments of pyargs() with the contents of an array, instead of hardcoding the values like the documents tell us.
I have this simple function I'm using for testing:
function s=my_test(varargin)
extraParams=cell(numel(varargin),2);
for i=1:numel(varargin)
str = varargin{i};
C = strsplit(str,'=');
extraParams{i,1}=C{1};
extraParams{i,2}=C{2};
end
s=extraParams;
end
If I use these inputs:
a=my_test('k1=v1','k2=v2','k3=v3')
I get:
a=
'k1' 'v1'
'k2' 'v2'
'k3' 'v3'
How can I pass these values to pyargs() like this?
pyargs('k1','v1','k2','v2','k3','v3')?
Thankful for any help you could bring :)

  0 Comments

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 22 May 2018
a = my_test(TheCellArray{:})

  2 Comments

Ajpaezm
Ajpaezm on 22 May 2018
Ahm... my_test is the function that generates the cell array. I want to populate pyargs() with the contents of that cell array.

Sign in to comment.


Stephen Cobeldick
Stephen Cobeldick on 22 May 2018
Edited: Stephen Cobeldick on 22 May 2018
tmp = a.';
pyargs(tmp{:})

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2016a