Data import from excel file with timestamp
4 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have an excel sheet with around 20 columns. I want to import the first 6 columns, with the first column that has a timestamp (date & time). The problem is that when I write the below code, the only data that is imported is from column B till F (instead from A till F as per code).
Data_Input = xlsread ('file.xlsx',"F:F")
Finally, is it possible that I import columns A and F only (therefore eliminating from B to E)?
Best Regards
4 件のコメント
Mohammad Sami
2020 年 1 月 10 日
編集済み: Mohammad Sami
2020 年 1 月 10 日
After the detectImportOptions, you can change the following property
See documentation of spreadsheetImportOptions for more details
https://www.mathworks.com/help/releases/R2017b/matlab/ref/spreadsheetimportoptions.html?s_tid=doc_ta
Excerpt from documentation
SelectedVariableNames — Subset of variables to import
character vector | string scalar | cell array of character vectors | string array | array of numeric indices
Subset of variables to import, specified as a character vector, string scalar, cell array of character vectors, string array or an array of numeric indices.
SelectedVariableNames must be a subset of names contained in the VariableNames property. By default, SelectedVariableNames contains all the variable names from the VariableNames property, which means that all variables are imported.
Use the SelectedVariableNames property to import only the variables of interest. Specify a subset of variables using the SelectedVariableNames property and use readtable to import only that subset.
To support invalid MATLAB identifiers as variable names, such as varible names containing spaces and non-ASCII characters, set the PreserveVariableNames parameter to true.
Example: opts.SelectedVariableNames = {'Height','LastName'} selects only two variables, Height and LastName, for the import operation.
Example: opts.SelectedVariableNames = [1 5] selects only two variables, the first variable and the fifth variable, for the import operation.
Example: T = readtable(filename,opts) returns a table containing only the variables specified in the SelectedVariableNames property of the opts object.
Data Types: uint16 | uint32 | uint64 | char | string | cell
採用された回答
Hiro Yoshino
2020 年 1 月 9 日
Do you like GUI?
How about using "import data" button from the ribbon.
You can import your file via GUI as shown below:
You can select the format with which the file is imported and also you can set the type of the variables.
I would reccomend you to import the data as a "table", and then try "table2timetable" command for the table data. This allows you to have many operations in time-wise.
if you want to know how to write down the process as script, you can choose an option from the list hidden behind the "import" botton. You can find "generate script" or similar there.
I'm sorry that they are shown in Japanese though I'm sure it still makes sense.
2 件のコメント
Hiro Yoshino
2020 年 1 月 9 日
Please have another look at the previous comment:
if you want to know how to write down the process as script, you can choose an option from the list hidden behind the "import" botton. You can find "generate script" or similar there.
you can generate the code as explained.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!