Name a variable that includes the cell name from a cell vector
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I am trying to assign names to the tables I am creating. I have a 1 by 20 cell vector called "Events" with each cell containing events like "NATO", "G20" etc. Now I need my tables to have names extracted from the cells with extentions like "NATO_a", "NATO_b" etc. I have tried Events(1)_a=table(); but it's not working. How do I extract the cell names and add extensions? Please advise.
11 Kommentare
Stephen23
am 2 Jul. 2019
Bearbeitet: Stephen23
am 2 Jul. 2019
@Syeda Amberin: note that putting meta-data into fieldnames will make your code fragile: consider what your code would do if one of the names was 1ABC, or AB@ (i.e. not a valid fieldname). Meta-data is data, and generally it should be stored in a variable, not in a fieldname or variable name.
Your code would be more robust if you just used indexing.
Antworten (1)
Syeda Amberin
am 26 Mär. 2019
2 Kommentare
Walter Roberson
am 26 Mär. 2019
s = [Events{1} '_a']
but note this does not create a table variable with that name.
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!