adding a constant to every term in a cell array

조회 수: 19 (최근 30일)
shobhit mehrotra
shobhit mehrotra 2015년 1월 27일
댓글: Image Analyst 2015년 1월 28일
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일
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개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by