Too many input arguments?

3 ビュー (過去 30 日間)
Sumer Vaid
Sumer Vaid 2015 年 3 月 25 日
編集済み: Stephen23 2015 年 3 月 27 日
I am getting the following problem when I try to run a cellfun of a length function across a cell array:
>> d_averages = cellfun(@length, values_data, values_data)
??? Error using ==> length
Too many input arguments.
Can someone help me?
  1 件のコメント
Stephen23
Stephen23 2015 年 3 月 27 日
編集済み: Stephen23 2015 年 3 月 27 日
Note that the output of length depends on the dimensions of the array, and can change unexpectedly. You might like to use numel instead.

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

回答 (1 件)

Radha Krishna Maddukuri
Radha Krishna Maddukuri 2015 年 3 月 25 日
Hi Sumer,
I understand that you wish to use 'cellfun' and you receive an error 'Too many Input Arguments'.
It is as the error states 'length' function can take only one input argument. You can verify this by:
>> help length
Also please try the following code snippet:
>> values_data = {1,2,3}
>> d_averages = cellfun(@length, values_data)
This code will produce the desired result without an error.
  3 件のコメント
Radha Krishna Maddukuri
Radha Krishna Maddukuri 2015 年 3 月 27 日
For your use case, you can try the following: say 3 cells each containing 3,4,2 cells respectively:
>> values_data = {{1,2,3},{1,2,3,4},{1,2}}
>> d_averages = cellfun(@length, values_data)
>> total = sum(d_averages)
From here you can see that d_Averages gives the individual lengths and 'sum' gives the total length (3+4+2 = 9).
Radha Krishna Maddukuri
Radha Krishna Maddukuri 2015 年 3 月 27 日
If you find the answer helpful, you can accept the answer, so that others who search for similar queries, may know that the answer was indeed helpful.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by