Effacer les filtres
Effacer les filtres

Extract a specific range of rows from an excel file using opts = detectImpo​rtOptions(​filename)

5 vues (au cours des 30 derniers jours)
I try to extract rows 191-222 from an excel file, and I use opts = detectImportOptions(filename)
However, by inspecting the weblink for this on MATLAB, I cannot find how to narrow down to a range, 191-222.
I tried
opts = detectImportOptions('tempDataTrollhFlygpl.xlsx', 'NumHeaderLines', 191-222, 'VariableNamingRule','preserve');
opts = setvartype(opts, 4, 'double');
D=readtable('tempDataTrollhFlygpl.xlsx', opts)
M = D(:,[3 4])
But that won't work. Any ideas how to limit opts = detectImportOptions to extract only within rows 191-222?
Thanks!

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 17 Fév 2024
Specify the data range to be read using the 'Range' option -
opts = detectImportOptions('tempDataTrollhFlygpl.xlsx', ...
'Range', '191:222', 'VariableNamingRule','preserve');
opts = setvartype(opts, 4, 'double');
D=readtable('tempDataTrollhFlygpl.xlsx', opts);
M = D(:,[3 4])
  8 commentaires
Dyuman Joshi
Dyuman Joshi le 19 Fév 2024
No, that is an expected behaviour. As M is a table, so using mean() directly on it calculates the mean of each variable.
If you want to calculate the mean of a particular variable in a table, use curly brackets to access the data in it or use the dot indexing as you did in plotting the data
mean(D{:,4})
%or
mean(D.Var4)
See mean and Access Data in Tables for reference.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by