I'm trying to add a constant to every term in the cell array. For example A = {[1 2 3] [4 5 6] [7 8 9]} and I want to add 5 to each term to create a cell array B= { [6 7 8] [ 9 10 11] [ 12 13 14]} Thanks!

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 1 月 27 日
編集済み: Azzi Abdelmalek 2015 年 1 月 27 日

1 投票

A = {[1 2 3] [4 5 6] [7 8 9]}
out=cellfun(@(x) x+5,A,'un',0)

2 件のコメント

shobhit mehrotra
shobhit mehrotra 2015 年 1 月 27 日
Perfect Thanks!
Image Analyst
Image Analyst 2015 年 1 月 28 日
But the question I have is why are you wanting to deal with the hassle of a cell array when you don't have to. You aren't mixing data types. You don't have rows or columns with different sizes. So why aren't you simply using a simple, regular numerical array??? Why make things complicated for yourself?

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

その他の回答 (0 件)

カテゴリ

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

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by