How do I remove "nested/deeper" layers of a cell?
23 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Jan
il 12 Dic 2022
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 Commenti
Stephen23
il 13 Dic 2022
Modificato: Stephen23
il 13 Dic 2022
"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.
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!