How do I remove "nested/deeper" layers of a cell?
조회 수: 25 (최근 30일)
이전 댓글 표시
Hi,
I have a cell called new_mat that has 2 levels (if I double click on a cell then another cell with the same value opens). Is it possible to remove the last/deepest layer somehow?
Thanks!
댓글 수: 0
답변 (1개)
Jan
2022년 12월 12일
You have posted a file, which contains the cell matrix called "new_mat". It does not have any second level. Therefore you cannot remove such a level also.
data = load('new_mat.mat')
% data =
% struct with fields:
% new_mat: {5×5 cell}
new_mat = data.new_mat;
댓글 수: 2
Stephen23
2022년 12월 13일
편집: Stephen23
2022년 12월 13일
"I was wondering if it is possible to not make it so that each cell contains a scalar but rather just the value itelf?"
What exactly does that mean? By definition, a scalar numeric is just a single value.
It might make sense to you, but you will have to explain using some other words, of what you actually want to achieve (not in terms of concepts that already have meanings in MATLAB and mean basically the same thing).
All cells (except one) of your cell array contain scalar numerics which by definition are single values:
S = load('new_mat.mat')
C = S.new_mat
I am guessing that you actually want to create a numeric array from this cell array: this is possible only after replacing the empty cells with some scalar values (e.g. NaN):
C(~cellfun(@isscalar,C)) = {NaN};
M = cell2mat(C)
Note that this does not make "...so that each cell contains a scalar but rather just the value itelf" for the simple reason that it is not a cell array and does not have cells. Numeric arrays have elements, but not cells. Perhaps this was the cause of your confusing request.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!