How do I remove "nested/deeper" layers of a cell?
26 次查看(过去 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 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!