フィルターのクリア

How to get readcell to read leading empty columns and rows in spreadsheet

48 ビュー (過去 30 日間)
Dabeer Ahmad
Dabeer Ahmad 2022 年 11 月 30 日
回答済み: Dabeer Ahmad 2022 年 12 月 5 日
Say I have an Excel file with some entries, offset so that they start at B2 instead of A1 (see image below):
So column A is completely empty, and row 1 is completely empty.
Can I use readcell() so that it includes the empty leading columns and rows? I want to do this without specifying a full range (i.e., 'A1:J50') because I don't know how large my data is. I want MATLAB to find that out for me. If I do readcell(file,'Range','A1'), then it omits the leading row because it's empty, which is the issue I'm facing.

採用された回答

Dabeer Ahmad
Dabeer Ahmad 2022 年 12 月 5 日
I figured out my issue. I was using 'Range' instead of 'DataRange.' Using
readcell(file,'DataRange','A1')
makes sure you read in starting from cell A1, even if there's leading missing rows and columns.

その他の回答 (1 件)

Arif Hoq
Arif Hoq 2022 年 11 月 30 日
please refer to this answer:
You don't need to specify the range. readtable, readcell, readmatrix functions can export all your data from excel.
  1 件のコメント
Dabeer Ahmad
Dabeer Ahmad 2022 年 12 月 5 日
I have a specific use case where it is easier for user to point to a piece of data by its cell location (i.e., 'B2'), but if I import the data using readcell() and there are empty leading rows or columns, then B2 might become item (1,1) in the cell array, which makes things complicated.
I know I can just
readcell(file,'Range','B2:B2')
in this case, but I would like to read in all the data first, then work with the matrix afterwards (that seems more efficient, especially because I'm extracting dozens of data points from a spreadsheet, and doing this for hundreds of sheets).
The link mentions you don't want to read in all empty cells, and I agree, but is there no way to just read in the leading empty rows and columns? Not the trailing ones?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by