Effacer les filtres
Effacer les filtres

Help iteration for loop and tables vertcat

5 vues (au cours des 30 derniers jours)
Nina Perf
Nina Perf le 27 Mai 2022
Modifié(e) : Nina Perf le 28 Mai 2022
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!

Réponse acceptée

Stephen23
Stephen23 le 27 Mai 2022
Modifié(e) : Stephen23 le 27 Mai 2022
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)
C = 45×2
1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 2 3
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

Plus de réponses (1)

Walter Roberson
Walter Roberson le 27 Mai 2022
Don't do this. put the tables in a cell array and use cell indexing instead of dynamic variable names.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by