필터 지우기
필터 지우기

Extract data range from nested cell array

조회 수: 6 (최근 30일)
mark
mark 2022년 7월 10일
댓글: Voss 2022년 7월 11일
Hi,
I have a 5x1 cell array where each cell is a sheet from an excel spreadsheet (5 sheets in total). I used 'readtable' to read in the excel data. I am trying to extract a data range from this nested cell array but I can't find the correct notation. This doesn't work:
cell_array_data_range = cell_array{1,1}{8,2}:{8,7}
error: Operator ':' is not supported for operands of type 'cell'.
I am trying to extract, from the first sheet (i.e. {1,1}), the 2nd till the 7th elements from row 8.
Thank you
  댓글 수: 3
mark
mark 2022년 7월 10일
cell_array=cell(5,1); %initialize
for w=1:5
cell_array{w,1} = readcell('My_Excel_file_name', 'Sheet', num2str(excel_sheet_names(w,1)));
end
%excel_sheet_names is a 5x1 string where each element is the sheet name of the excel file
thank you for your reply
mark
mark 2022년 7월 10일
My mistake, I forgot i changed 'readtable' for 'readcell'

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

채택된 답변

Voss
Voss 2022년 7월 10일
This syntax should work "to extract, from the first sheet (i.e. {1,1}), the 2nd till the 7th elements from row 8":
cell_array{1,1}(8,2:7)
Or, simpler:
cell_array{1}(8,2:7)
which we can do because cell_array has only one non-singleton dimension (in this case cell_array is a column vector).
If you used readtable, then either of those two expressions returns a 1x6 table; if you used readcell, then they give you a 1x6 cell array.
  댓글 수: 2
mark
mark 2022년 7월 11일
Thank you so much, this is exactly what I was looking for!
Voss
Voss 2022년 7월 11일
You're welcome!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by