フィルターのクリア

ndgrid with unknown number of output arguments

5 ビュー (過去 30 日間)
Jin
Jin 2011 年 4 月 19 日
Hi, I am trying to make something work using ndgrid. Here is a copy of the response:
a={0:5,0:1}
a =
[1x6 double] [1x2 double]
>> b=cell(1,2)
b =
[] []
>> b{1:2}=ndgrid(a{:}) ??? The right hand side of this assignment has too few values to satisfy the left hand side.
Obviously ndgrid cannot recognize b{1:2} as two output arguments. The truth is I generally don't know how many elements are there in "a" a priori. Is there an easy way to deal with it, aside from using "eval"? I'm using version 2010a. Thank you very much.
Jin
  2 件のコメント
Laura Proctor
Laura Proctor 2011 年 4 月 19 日
Is there a reason that you're using cell arrays rather than doubles in this case? What is it you're trying to do with NDGRID?
Jin
Jin 2011 年 8 月 1 日
I may not know a priori how many vectors in "a{:}" are plaided, thus how many output are there going to be. I could write
[b1,b2,b3,...,bn]=ndgrid(a1,a2,...,an)
but I don't know what n is.

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

採用された回答

Oleg Komarov
Oleg Komarov 2011 年 4 月 19 日
You were very close:
a = {0:5,0:1,3:10};
b = cell(1,numel(a));
[b{:}] = ndgrid(a{:});

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by