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)
0 个评论
采纳的回答
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 个评论
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!