times function for argument of type cell?

1 回表示 (過去 30 日間)
Chiara Scarpellini
Chiara Scarpellini 2021 年 8 月 31 日
編集済み: Walter Roberson 2021 年 9 月 1 日
I have an argument of type cell (2785 x 20) and I need to multyply every cell per 100 and divide it per 785. Thus I need a function like times for vectors

採用された回答

Star Strider
Star Strider 2021 年 8 月 31 日
It is necessary to include the cell array as an argument to cellfun:
C = num2cell(randi(9,4, 5))
C = 4×5 cell array
{[2]} {[2]} {[7]} {[7]} {[2]} {[9]} {[8]} {[1]} {[5]} {[4]} {[1]} {[4]} {[4]} {[9]} {[7]} {[3]} {[5]} {[8]} {[7]} {[4]}
percentages = cellfun(@(x)times(x,100/787), C)
percentages = 4×5
0.2541 0.2541 0.8895 0.8895 0.2541 1.1436 1.0165 0.1271 0.6353 0.5083 0.1271 0.5083 0.5083 1.1436 0.8895 0.3812 0.6353 1.0165 0.8895 0.5083
.
  4 件のコメント
Chiara Scarpellini
Chiara Scarpellini 2021 年 9 月 1 日
Operator '*' is not supported for operands of type 'cell'
Walter Roberson
Walter Roberson 2021 年 9 月 1 日
編集済み: Walter Roberson 2021 年 9 月 1 日
What is the output of
unique(cellfun(@class, matrix_substances, 'uniform', 0))
The message you are getting suggests that there is at least one location inside matrix_substances where the entry is a cell array instead of being a single number or [] .

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by