Filter löschen
Filter löschen

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

6 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 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])
  8 Kommentare
Dyuman Joshi
Dyuman Joshi am 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
mean(D{:,4})
%or
mean(D.Var4)
See mean and Access Data in Tables for reference.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by