readtable error in Matlab

조회 수: 28 (최근 30일)
Jayden Yeo
Jayden Yeo 2023년 3월 1일
댓글: Jeremy Hughes 2023년 3월 3일
Hi,
I am reading a table from a csv file using the readtable command, and specifying specic range. However when I run the line, the following error appears. "Error using readtable. Invalid parameter name: Range". Anybody know what is wring? I am running the code on R2015b version of Matlab.
data = readtable('data.csv','Range','A1:C10');
  댓글 수: 2
Rik
Rik 2023년 3월 1일
Did you check the documentation in R2015b to confirm this parameter exists and has this name?
Jayden Yeo
Jayden Yeo 2023년 3월 1일
Yes, it was introduced in R2013b. Also I can run it in R2022b. Just wondering why it cannot run in R2015b?
data = readtable('data.csv','Range','A1:C10');

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2023년 3월 1일
The option you are trying to use only works for spreadsheet files. A csv file is just a text file and does not actually describe ranges. You will have to read the entire file and limit the result in your own Matlab code:
data = readtable('data.csv');
data = data(1:10,1:3);
Apparently R2022b is less strict about this limitation.
  댓글 수: 1
Jeremy Hughes
Jeremy Hughes 2023년 3월 3일
If I recall, the "Range" was added for text files in R2019a or 19b.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Pratheek
Pratheek 2023년 3월 1일
Hi Jayden Yeo,
You are facing this issue since, in R2015b version of MATLAB, comma-delimited text files(.txt, .dat, .csv) allow only limited parameters.
They are - ReadVariableNames, ReadRowNames, TreatAsEmpty, HeaderLines, Format, DateLocale, FileEncoding.
For Spreadsheet files(.xls, .xlsx, .xlsb, .xlsm, .xltm, .xltx, .ods) we can use these parameters- ReadVariableNames, ReadRowNames, TreatAsEmpty, Sheet, Range, Basic.
As you are working with a .csv file you can't use Range parameter
A workaround for you issue can be
T = readtable('myfile.csv');
T_range = T(startRow:endRow, startCol:endCol);
  댓글 수: 1
Jayden Yeo
Jayden Yeo 2023년 3월 2일
Thanks. Your method works too.

댓글을 달려면 로그인하십시오.

카테고리

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

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by