I have two cells:
table1 = cell(1,1);
table2 = cell(1,1);
table1{1}(:,1) = [1 2 3];
table1{1}(:,2) = [4 5 6];
table2{1}(:,1) = [3 6 5];
table2{1}(:,2) = [4 9 7];
>>table1{1}
ans =
1 4
2 5
3 6
>> table2{1}
ans =
3 4
6 9
5 7
What I want is two compute the sum of all the columns of each table. For example, for table1:
sum (column1 , column2) = result_column.
By the way I wrote the code below:
table_list = cell(2, 1);
for i=1:2
table_list{i} = strcat('table', num2str(i)); % table_list{1}='table1', table_list{2} ='table3'
end
sum = zeros(3,1);
for i=1:2
x = table_list{i};
for j=1:2
sum = sum + x{1}(:, j) % here I got always the error below
end
end
What is my problem:
I always get the error
??? Cell contents reference from a non-cell array
object.
So I don't know how to concatenate 'table' with 'i' in order to get table1{1}(...) and table2{1}(...).
Any help will be very appreciated!
sum(table1{1},1)andsum(table2{1},1)?xis clearly a string, not a cell array. Why not just put the matrices directly in a 2x1 cell array and save mucking about with variable names at all?