フィルターのクリア

how to write code to add some scalar value to each 4by4 cell of a dataset?

3 ビュー (過去 30 日間)
bidlee devi
bidlee devi 2018 年 5 月 4 日
編集済み: Jan 2018 年 5 月 13 日
hello everyone. need help.I want to add some scalar value to each 4by4 cell of size 64by64. for example : add 10 to first 4by4 cell . then add 20 to the other 4by4 cell and so forth. How do i write the code in matlab. I am new so need your help. Thanks!
  1 件のコメント
Jan
Jan 2018 年 5 月 13 日
編集済み: Jan 2018 年 5 月 13 日
It is not clear to me, what the inputs are. Posting a small example would be useful. Perhaps:
C = cell(4, 4);
for iC = 1:4
C{iC} = rand(64, 64);
end
If this matches your inputs, what exactly is "the first 4by4 cell" and what is "the other"?

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

回答 (2 件)

Jan
Jan 2018 年 5 月 13 日
編集済み: Jan 2018 年 5 月 13 日
If these are your inputs (see my comment):
C = cell(4, 4);
for iC = 1:4
C{iC} = rand(64, 64);
end
toAdd = [10, 20, 30, 40];
then a loop is working:
for iC = 1:numel(C)
C{iC} = C{iC} + toAdd(iC);
end
Or maybe you mean:
toAdd = 10 * (1:(64*64)); % Example data
for iC = 1:numel(C)
C{iC} = C{iC} + toAdd;
end
This can be achieve by arrayfun or cellfun also, but I consider a loop to be more clear and easy.

Ameer Hamza
Ameer Hamza 2018 年 5 月 13 日
You can do it using arrayfun():
cellArray = ... % 64x64 array of cells
% define a 64x64 'addMatrix', its elememnts will be added to corrosponing cell of 'cellArray'
addMatrix = [10 20 30, ..... 640;
....;
....;
....]; % define a 64x64 matrix
result = arrayfun(@(x, y) x{:} + y, cellArray, addMatrix, 'UniformOutput', 0);

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by