Access data from table and assign to variables
Mostra commenti meno recenti
Hi, I am making a program with excel file already converted to table and now I need to code such that when a user gives an input a certain coloumn is taken and then assign certain variables to some particular blocks in that row.
example:
Vehicle speed fuel
Car 50 2
Bike 20 1
Cycle 5 0
Like user gives input as Bike. then I need to assign variables created like speed and fuel to use in further equations.
4 Commenti
Image Analyst
il 27 Ago 2021
What type of variable do you want to create? A new table? Add a row to an existing table? A new instance of a class variable? A new structure, perhaps added onto an existing structure array?
Dhananjay Singh
il 27 Ago 2021
Stephen23
il 27 Ago 2021
"...then I need to assign variables created like speed and fuel to use in further equations."
Why not just access the data directly from the table?
Dhananjay Singh
il 27 Ago 2021
Risposta accettata
Più risposte (1)
Picking up from @Ive J's example, but use 'Vehicle' as Row Labels to take advantage of native table indexing:
t = table([50; 20; 5], [2; 1; 0], 'VariableNames', ["speed", "fuel"], 'RowNames', ["Car"; "Bike"; "Cycle"])
t("Bike", ["speed", "fuel"]) % or if you want all variables, t("Bike", :)
Categorie
Scopri di più su Tables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!