Help iteration for loop and tables vertcat
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi,
- I have a varible C which is a 45x2 double with the possible combinations of numbers, #, from 1 to 10 (meaning 10 birds).
- Per bird I have a table named tablevars#, where # are numbers from 1 to 10.
- I want to have inside the for cycle the total table that will change per combination (matches each row of C per iteration i).
tablevars1
tablevars2
...
w = [1:10];
p = 2;
C = nchoosek(w,p);
u = length(C);
for i = 1:u
total = vertcat(?);
...
end
Thank you!
댓글 수: 1
채택된 답변
Stephen23
2022년 5월 27일
편집: Stephen23
2022년 5월 27일
Using one cell array will be much simpler (and more efficient) than your approach of numbering the variable names:
w = 1:10; % removed superfluous square brackets
p = 2;
C = nchoosek(w,p)
tbl = { table(..), table(..), table(..) .. }; % cell is better than numbered variable names.
for k = 1:size(C,1)
idx = C(k,:);
out = vertcat(T{idx})
..
end
댓글 수: 0
추가 답변 (1개)
Walter Roberson
2022년 5월 27일
Don't do this. put the tables in a cell array and use cell indexing instead of dynamic variable names.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!