필터 지우기
필터 지우기

Sum vector to each vector row in cell array

조회 수: 1 (최근 30일)
Miguel Romanello Joaquim
Miguel Romanello Joaquim 2018년 6월 28일
댓글: Miguel Romanello Joaquim 2018년 6월 28일
I have a cell array where all its matrices are m-by-3, where m can change from matrix to matrix. I want to sum a vector to each row in the cell array. For example, a function which turns A to B by adding [0 0 1]:
A = {[1 2 3; 0 0 0]} {[9 9 0; 1 2 3]}
B = {[1 2 4; 0 0 1]} {[9 9 1; 1 2 4]}
Is this possible? I am not very familiar with 'cellfun'.

채택된 답변

Stephen23
Stephen23 2018년 6월 28일
편집: Stephen23 2018년 6월 28일
For MATLAB versions R2016b+:
cellfun(@(m)m+[0,0,1],A,'uni',0)
For earlier versions:
cellfun(@(m)bsxfun(@plus,m,[0,0,1]),A,'uni',0)
  댓글 수: 1
Miguel Romanello Joaquim
Miguel Romanello Joaquim 2018년 6월 28일
Thank you! I was imagining something like that earlier but unfortunately didn't have the 'uni' part settled down.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by