subtracting a vector from cell array of same size

2 ビュー (過去 30 日間)
shobhit mehrotra
shobhit mehrotra 2015 年 2 月 15 日
コメント済み: shobhit mehrotra 2015 年 2 月 15 日
Hello, I have a vector
V= [1, 5, 7, 9]
and I have a cell array of the same size
C = {cell 1, cell 2, cell 3, cell 4,}.
How would I subtracted V from C. I want to subtract V(1)) from every value in cell 1, and subtract V(2) from every value in cell 2, etc...
All of the cells contains only integers

採用された回答

Geoff Hayes
Geoff Hayes 2015 年 2 月 15 日
Shobhit - you could use arrayfun to perform the subtraction on each element of your cell array. Something like
C = {randi(255,43,1) randi(255,32,1) randi(255,95,1) randi(255,99,1)};
V = [1, 5, 7, 9];
Cp = arrayfun(@(k) C{k}-V(k),1:4,'UniformOutput',false);
where Cp is the result of subtracting each element of V from the corresponding cell in C.
  1 件のコメント
shobhit mehrotra
shobhit mehrotra 2015 年 2 月 15 日
Worked perfectly Thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by