how to store the matrix in a single table after every iteration
조회 수: 1 (최근 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
댓글 수: 0
답변 (2개)
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?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!