Effacer les filtres
Effacer les filtres

how to identify matlab identify a cell(title) in excel and use it as a variable.

3 vues (au cours des 30 derniers jours)
Nasir
Nasir le 7 Juin 2019
Commenté : dpb le 7 Juin 2019
i am writing a code and need matlab to find a cell that contains text , where that text may be in variable locations in different excel sheets. using simple notations such as A for a column header works and is simple , however if the column header is for example "1221 Car Speed" how would i be able to do so ?
the code below (where E and B are column headers ) shows one way it can be used for simple variables but i am not sure how to do this with more complicated titles , ideally if there is also a way to make it have some sort of user input that would be the best case.
t1 = readtable('test1.xlsx')
mask = t1.E == 112;
B22 = t1.B(mask)

Réponse acceptée

dpb
dpb le 7 Juin 2019
Matlab turns column header text into allowable variable names by using the underscore to fill in spaces and appending suffix integers to multiple variables of the same name if those exist. Using the variable names thus created works the same as you've shown for simple variables.
Alternatively, don't read the titles but let default to the 'VarN' syntax but return the header line as the description line that is in the Properties stuct. You can use text search operations on that cell array to find any particular string location and retrieve the assocated column/variable by name or column index.
Asking user for input from dropdown listbox of that list would be simple as one way...
  2 commentaires
Nasir
Nasir le 7 Juin 2019
so how would i write out the code to reference that cell/column, what would the code look like ?
Note: i can not change the excell file headers
dpb
dpb le 7 Juin 2019
Look at
t1 = readtable('test1.xlsx');
t1.Properties.VariableNames
and then documentation for contains and/or strfind and friends for lookup, matching...

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by