Data import from excel file with timestamp
조회 수: 5 (최근 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!