how to store the matrix in a single table after every iteration

2 次查看(过去 30 天)
suppose i have a matrix which size is always same but value does not same it will be change after every iteration for i=1:2 matrix result after iteration 1
A B
1.21 21.32
21.32 32.21
89.11 32.87
matrix result after iteration 2
A B
21.32 43.21
43.54 78.32
77.23 99.1
end now i wish to add new matrix in the next column of table when new iteration will be run. all array values are in the table after iteration over.
A B A B
1.21 21.32 21.32 43.21
21.32 32.21 43.54 78.32
89.11 32.87 77.23 99.1

回答(2 个)

Thomas Koelen
Thomas Koelen 2015-4-29
have a look at this inbuild function:

Guillaume
Guillaume 2015-4-29
You can't have duplicate variable names (column headers) in a table, so your desired output is not possible.
If you use different column names, then joining two tables is trivial:
t1 = array2table([1.21 21.32; 21.32 32.21; 89.11 32.87], 'VariableNames', {'A1', 'B1'});
t2 = array2table([21.32 43.21; 43.54 78.32; 77.23 99.1], 'VariableNames', {'A2', 'B2'});
tmerged = [t1 t2]
You could generate the variable names for each loop with:
varnames = cellfun(@(prefix) sprintf('%s%d', prefix, i), {'A', 'B'}, 'UniformOutput', false);
I'm not sure it's a good idea, though. Why not concatenate the rows instead of the columns?

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by