how to convert array of cells within array of cells in single cell array
3 views (last 30 days)
Show older comments
A= {<1x1 cell> <1x3 cell> [4,0] <1x4 cell>}
where
<1x1>= [2,3,4]
<1x3>= [ ] [3,4] [3,8,13]
<1x4>= [9,4] [9,8,13] [ ] [9,14,19]
so i want my answer to be in form of a single array of cells as below,
B={ [2,3,4] [3,4] [3,8,13] [4] [9,4] [9,8,13] [9,14,19] }
1 Comment
Image Analyst
on 26 Dec 2021
OK I see that you want null cells to be left out, but how did cell number 4 come to contain [4]:
B={ [2,3,4] [3,4] [3,8,13] [4] [9,4] [9,8,13] [9,14,19] }
The third cell of A contains a vector [4, 0]. But B{4} is [4]. What happened to the 0? Do you want to exclude zeros also for some reason?
Answers (1)
Stephen23
on 26 Dec 2021
Edited: Stephen23
on 26 Dec 2021
A = {{[2,3,4]},{ [],[3,4],[3,8,13]},{[4,0]},{[9,4],[9,8,13],[],[9,14,19]}}
B = [A{:}]
3 Comments
Stephen23
on 26 Dec 2021
Or without the anonymous function:
B(cellfun(@isempty,B)) = [];
"...so i want my answer to be in single cell array"
and is what my answer gives you.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!