how to sum cell elements in a dynamic cell table
古いコメントを表示
Hi guys, I have a challenging problem here :
A{b,i} is a cell table with b lines and i columns. the problem is that b can be any integer (dynamic variable) while i is a fixed number. The problem is the following : how to sum elements by varying the column index of the first row while maintaining column indexes of other rows constant, and again fix column index of all the rows except second row and so on. Note that in case of try to use for loops to vary column indexes that we will need b for loops to be generated dynamically which is irrelevant. You will find more explanation in the following
for b = 1:L
for i = 1:16
A{b,i} = ones(1,8);
end
end
Question : how to sum table elements columnwise according to how many rows we are having. Example : in case of two rows we will have 16x16 sum values, in case of three rows we will have 16x16x16 sum values, etc...
5 件のコメント
Jan
2022 年 6 月 19 日
The term "cell table" is confusing. "Cell" and "table" are specific types in Matlanb, but I do not know, what a "cell table" is. Your data look like a cell matrix, which contain vectors as elements.
This is not clear to me also: "how to sum elements by varying the column index of the first row while maintaining column indexes of other rows constant, and again fix column index of all the rows except second row and so on." A small example would be useful. Do you want to combine all elements of one vector with the elements of other vectors? If so, what exactly do you want to sum up?
Akram RAYRI
2022 年 6 月 19 日
Jan
2022 年 6 月 19 日
In the question you show a cell matrix containing vectors. Now the cell matrix contains scalars. Do you want to get the combinations between the elements of the vectors, of of the rows of the cel matrix?
Akram RAYRI
2022 年 6 月 19 日
Image Analyst
2022 年 6 月 19 日
Can you just stop making us guess? And making us have to make up sample data which may or may not be the form you have? Or having to make some MATLAB code to generate the printout of A you gave above?
Simply attach your cell array in a .mat file with the paperclip icon.
save('answers.mat', 'A');
after you read this link:
採用された回答
その他の回答 (1 件)
Is this similar to what you want to do? (Using 5 columns here instead of 16, and using 3 rows.)
data = (1:5).*[1;7;20]
[L,M] = size(data);
result = repmat({0},1,L);
c_data = num2cell(data.',1);
siz = ones(1,L);
for ii = 1:L
for jj = 1:ii
siz(jj) = M;
result{ii} = result{ii}+reshape(c_data{jj},siz);
siz(jj) = 1;
end
end
disp(result)
disp(result{1})
disp(result{2})
disp(result{3})
4 件のコメント
Akram RAYRI
2022 年 6 月 19 日
Voss
2022 年 6 月 19 日
Scroll down? It's 5x5x5.
Akram RAYRI
2022 年 6 月 19 日
Akram RAYRI
2022 年 6 月 19 日
カテゴリ
ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!