i need to create variable name using for loop from a table
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vijayagopi Ramachnadran
am 23 Feb. 2022
Beantwortet: Vijayagopi Ramachnadran
am 28 Feb. 2022
i'm trying to assign each column from my table to each separate variable with header as variable name using for loop
i couldn't find any function that directly does it
i've used fo loop to index tha data and i'm able to pront the collumns separately
when i try to assign contents of a table as variable name it is not allowing to go ahead
the following is my code
tableA has headers as variable names which are loaded in table T
file =("WLTCshortened_2.txt")
opts = detectImportOptions(file);
opts.DataLines = 3;
tableA=readtable(file,opts)
T = readtable('variable_name.xlsx', 'Range','A2:BV2', 'ReadVariableNames',false)
for i=(1:74)
rowname =string(table2cell(T(1,i)))
y=rowname.char
string(y)=(tableA.(string(y)))
end
9 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 23 Feb. 2022
Can you define variables with numbered names like X1, X2, X3, ... ? Yes.
Should you do this? Generally we recommend against it. See that page for alternatives you should use instead.
3 Kommentare
Steven Lord
am 23 Feb. 2022
Since you mentioned you want to do this in the context of working with Simulink, I'd consider using a model workspace or perhaps a data dictionary. See the documentation for more information on how to programmatically interact with a model workspace and this documentation section for more information about managing design data in general.
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!