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

1 回表示 (過去 30 日間)
singh
singh 2015 年 4 月 29 日
回答済み: Guillaume 2015 年 4 月 29 日
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 Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by