load all the variables from .csv file in workspace as input to "From Workspace" block?
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a simulink model in that am using From Workspace block to take input data from the workspace. Also i have a .csv file i need to load all the variables to the workspace for the model like (if the filename.csv file contains age, number and data.. i need to load each variables in the workspace)
I also used T = readtable(filename.csv) this is creating a T variable in the workspace, but i want to load all the variable( like age, number and etc...) not the T variable.
and also i use the import data option in the variable environment that is aslo not working for my need..
please help on this ..
Thanks in advance....
0 comentarios
Respuestas (1)
Tushar Behera
el 3 de Feb. de 2023
Hi Muralidharan
I believe you want to import data from a excel file with their respective variable names such as age, number etc. instead of the whole table "T".
You can use the readtable function in MATLAB to load the data from the .csv file into the workspace and then extract the variables (e.g. age, number, etc.) you need using dot notation (e.g. T.age) or into separate variables using the following psuedocode:
T = readtable(filename.csv);
age = T.age;
number = T.number;
data = T.data;
This will load the variables age, number, and data into the workspace from the .csv file. Then you can use these variables as inputs in your Simulink model.
Hope this resolves your query.
Regards,
Tushar
2 comentarios
Sarah Gilmore
el 3 de Feb. de 2023
Hi Muralidharan,
>> [age, number, data] = readvars(filename);
This will return the variables in filename as separate variables.
Best,
Sarah
Ver también
Categorías
Más información sobre Sources en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!