How to make matlab variables named as excel header

12 vues (au cours des 30 derniers jours)
Drewsky3
Drewsky3 le 26 Sep 2019
I have a very generic excel file I am importing intp matlab.
First row is strings as the header names.
every row beneath that is a string (date) or numeric value. I want to make a matlab array as the header of each column, and the data in the array is the numeric value for each corresponding row. What would be the best method to do this? I have tried a few other methods found on here using evalin() and no luck.
xls file attached for reference.

Réponses (2)

Bob Thompson
Bob Thompson le 26 Sep 2019
It sounds like readtable might be what you're looking for. I don't think it's exactly what you're asking, but it should recognize the column headers as variable names, and then assign data accordingly.
  4 commentaires
Drewsky3
Drewsky3 le 26 Sep 2019
I explained what I want to do in the main queation. I want to make a matlab array with the excel header as the variable name.
ie: t pt_001
1 5
2 17
3 45
so I want an array of type double, titles as the header (t, and pt_001)
so I will end with t=[1 2 3]
pt_001 = [5 17 45]
Bob Thompson
Bob Thompson le 26 Sep 2019
Mmm, I see now. The only way to create variables in that manner is with the eval command, which nobody ever recommends because it is terribly inefficient and leads to very bad coding practices.
I don't mean to sound like a broken record, but again I recommend using the table class variable. If you want to refer to a specific set of data then you can call the data using dot notation.
>> T = readtable('FIT-03801L1.xls');
>> T.t
ans =
1
2
3
>>
Alternatively, you can read the information in with readtable and then convert the data into a structure array, which is handled in much the same way.
>> T = readtable('FIT-03801L1.xls');
>> T = table2struct(T);

Connectez-vous pour commenter.


Drewsky3
Drewsky3 le 26 Sep 2019
Thanks for your help, I've actually made some progress with the eval funtion. Though it does lead to bad coding practives I've got extremely varried datasets that I'm working with. Thanks for your time.

Produits


Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by