Sum vector to each vector row in cell array

1 次查看(过去 30 天)
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
Thank you! I was imagining something like that earlier but unfortunately didn't have the 'uni' part settled down.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by