Match cell array names with table names

1 vue (au cours des 30 derniers jours)
Paul
Paul le 21 Août 2025
Modifié(e) : Stephen23 le 22 Août 2025
I have 20 tables with the following table names:
str =
{'W1' }
{'S1' }
{'W2' }
{'W3' }
{'S2' }
{'S3' }
{'W4' }
{'S4' }
{'S5' }
{'W5' }
{'S6' }
{'W6' }
{'S7' }
{'W7' }
{'S8' }
{'W8' }
{'W8' }
{'W10'}
{'S9' }
{'S10'}
The letters W and S refer traffic flow in the west and south directions. The str is ordered.
I want to analyze the interaction in pairs. For example, first analyze interactions between 'W1' and 'S1', next between 'S1' and 'W2', and so forth with my function called CF. Continuing with the example:
Calculate a new S1 = CF(W1,S1).
Next calcutale a new W2 = CF(S1,W2) and so forth.
  1 commentaire
Stephen23
Stephen23 le 21 Août 2025
Modifié(e) : Stephen23 le 22 Août 2025
You forgot to tell us the most important information: how did you get twenty badly-named** variables into the workspace? Did you write them all out by hand? Did you LOAD them? The point at which you created those twenty vairables in the workspace is the best place to fix the bad data design, by e.g. LOADing into an output variable or indexing into one array withing a loop. But it all depends on how those arrays are created, which you have not told us.
**because forcing meta-data into variable names invariably leads users into writing slow, complex, inefficient code:

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 21 Août 2025
Modifié(e) : Matt J le 21 Août 2025
You shouldn't have 20 tables. You should have 20 struct fields,
Tables.W1=... %a table
Tables.S1=... %another table
and so forth. Then you can freely refer to them dynamically,
for i=1:numel(str)
for j=1:numel(str)
Tables.(str{i}) = CF( Tables.(str{j}), Tables.(str{i}) ) ;
end
end

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Produits


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by