Sum up a value to a row and create new colum at the end of the cell

조회 수: 1 (최근 30일)
How can I add to a row 1 unit? I have the following cell:
A= {12 1996 1999
15 1999 2002
26 1997 2001
43 1999 2008
59 1995 2000}
I would like the output to be:
Output={A= {12 1996 1999 2000
15 1999 2002 2003
26 1997 2001 2004
43 1999 2008 2009
59 1995 2000 2001}
I tried this:
A(:,end+1) = cell2mat(A(:,3))+1;
It gives me the error: 'Conversion to cell from double is not possible.'
But if I take out the 'cell2mat', I get the error: 'Undefined function 'plus' for input arguments of type 'cell'.'
Does someone know how to solve the problem? Thank you

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 27일
편집: Azzi Abdelmalek 2014년 7월 27일
cell2mat(cellfun(@(x) [x x+1],A,'un',0))
[A num2cell([A{:}]+1)']
  댓글 수: 2
Maria 2014년 7월 27일
ok I omited the part that I have more rows that I presented in the example. I believe that's why the codes are not working. I will edit. Sorry
Maria 2014년 7월 27일
thanks, it works perfectly like this!
A=[A num2cell([A{:,3}]+1)'];

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 7월 27일
A(:,end+1) =cellfun(@(x)x+1,A(:,end),'un',0)


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


Community Treasure Hunt

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

Start Hunting!

Translated by