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

3 次查看(过去 30 天)
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)

采纳的回答

dpb
dpb 2019-6-7
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 个评论
Nasir
Nasir 2019-6-7
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 2019-6-7
Look at
t1 = readtable('test1.xlsx');
t1.Properties.VariableNames
and then documentation for contains and/or strfind and friends for lookup, matching...

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by