Match cell array names with table names

3 Ansichten (letzte 30 Tage)
Paul
Paul am 21 Aug. 2025
Bearbeitet: Stephen23 am 22 Aug. 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 Kommentar
Stephen23
Stephen23 am 21 Aug. 2025
Bearbeitet: Stephen23 am 22 Aug. 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:

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt J
Matt J am 21 Aug. 2025
Bearbeitet: Matt J am 21 Aug. 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

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Produkte


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by