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

5 次查看(过去 30 天)
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!

采纳的回答

Dyuman Joshi
Dyuman Joshi 2024-2-17
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 个评论
Dyuman Joshi
Dyuman Joshi 2024-2-19
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.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by