MATLAB Answers

Summing elements of an array

1 ビュー (過去 30 日間)
Gian Carpinelli
Gian Carpinelli 2018 年 4 月 13 日
コメント済み: Stephen Cobeldick 2018 年 4 月 13 日
Hi, so for example I have P such that: P =
3×1 cell array
The matrix P can be a n x 1 cell array, where n is any positive integer, and can only hold numbers. Ive tried to sum these numbers using sum(P) but keep getting the error ' Undefined function 'sum' for input arguments of type 'cell'. '. Any ideas on how I could do this? thank-you.

  1 件のコメント

Stephen Cobeldick
Stephen Cobeldick 2018 年 4 月 13 日
@Gian Carpinelli: why are you storing numeric data in a cell array? It would be simpler to store it in a numeric array.


回答 (2 件)

KL 2018 年 4 月 13 日
編集済み: KL 2018 年 4 月 13 日
But why would you store it in cell array? If they are all numeric, better use a numeric array.

  0 件のコメント


M 2018 年 4 月 13 日
You can use either

  0 件のコメント


Community Treasure Hunt

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

Start Hunting!

Translated by