How to multiply each numeric element in a cell array with a given number

I have got a cell array with numbers and one descriptive text element in a column, and I want to multiply each of these elements with the same numerical value,while not messing up this cell array structure. How can I do this

回答 (1 件)

James Tursa
James Tursa 2020 年 3 月 27 日
Do you mean something like this?
>> C = {'text'; 1; 1:2; 1:3}
C =
4×1 cell array
{'text' }
{[ 1]}
{1×2 double}
{1×3 double}
>> f = 5;
>> C(2:4) = cellfun(@(c)f*c,C(2:4),'uni',false)
C =
4×1 cell array
{'text' }
{[ 5]}
{1×2 double}
{1×3 double}
>> C{2}
ans =
5
>> C{3}
ans =
5 10
>> C{4}
ans =
5 10 15

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

製品

リリース

R2018b

タグ

質問済み:

2020 年 3 月 27 日

回答済み:

2020 年 3 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by