Clear Filters
Clear Filters

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

5 views (last 30 days)
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?

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 17 Feb 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])
Dyuman Joshi
Dyuman Joshi on 19 Feb 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
See mean and Access Data in Tables for reference.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!