필터 지우기
필터 지우기

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개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by