Data import from excel file with timestamp

조회 수: 4 (최근 30일)
Stefan Azzopardi
Stefan Azzopardi 2020년 1월 9일
편집: Mohammad Sami 2020년 1월 10일
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
Stefan Azzopardi
Stefan Azzopardi 2020년 1월 9일
Hi Mohammed,
I used readtable function and I managed to import excel sheet range from columns A to F (as needed). using detectImportOption, should I be able to remove the unnecessary columns?
Mohammad Sami
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
SelectedVariableNamesSubset 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
Hiro Yoshino 2020년 1월 9일
Do you like GUI?
b.PNG
How about using "import data" button from the ribbon.
You can import your file via GUI as shown below:
d.PNG
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
Stefan Azzopardi
Stefan Azzopardi 2020년 1월 9일
This is one way of working but the problem is that I need to import data from a number of excel sheets (around 60) and that would end up to take more time. That was why I was trying to code for one and then copy for the rest of the excel sheets.
Hiro Yoshino
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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2012b

Community Treasure Hunt

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

Start Hunting!

Translated by