Using a string to pass input argument to a function

3 ビュー (過去 30 日間)
Chiara Innocente
Chiara Innocente 2021 年 2 月 26 日
コメント済み: Chiara Innocente 2021 年 2 月 26 日
Hi,
I have to use the function ndgrid different times, each time with a different number of input and output arguments.
I would like to make all automatic, so i tried to concatenate in a string what i have to pass as argument both in output and input but it doesn't work.
Here is the code I used.
[output]=ndgrid(=input);
where
input is {'[table{1,1}(1,2) table{1,1}(1,3)], [table{1,1}(2,2) table{1,1}(2,3)], [table{1,2}(1,2) table{1,2}(1,3)]'}
and
output is {'p11, p12, p21'}
any ideas of how I can make it works?
  2 件のコメント
Stephen23
Stephen23 2021 年 2 月 26 日
C = {1:3,4:6,7:9}
C = 1x3 cell array
{1×3 double} {1×3 double} {1×3 double}
[C{:}] = ndgrid(C{:})
C = 1x3 cell array
{3×3×3 double} {3×3×3 double} {3×3×3 double}
Chiara Innocente
Chiara Innocente 2021 年 2 月 26 日
Thanks, now it works!

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2021 年 2 月 26 日
Use comma-separated lists (CSL). The "How to Use the Comma-Separated Lists" section on that page shows both how to use CSL to pass inputs into a function and how to accept outputs returned from a function.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by