Data import from excel file with timestamp
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Stefan Azzopardi
le 9 Jan 2020
Modifié(e) : Mohammad Sami
le 10 Jan 2020
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 commentaires
Mohammad Sami
le 10 Jan 2020
Modifié(e) : Mohammad Sami
le 10 Jan 2020
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
Réponse acceptée
Hiro Yoshino
le 9 Jan 2020
Do you like GUI?
![b.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260703/b.png)
How about using "import data" button from the ribbon.
You can import your file via GUI as shown below:
![d.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260704/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 commentaires
Hiro Yoshino
le 9 Jan 2020
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!