Problem 152. Create a cell array out of a struct
Create a cell array out of a (single) struct with the fieldname in the first column and the value in the second column:
in:
S.foo = 'hello'; S.bar = 3.14;
out:
{'foo', 'hello'; 'bar', 3.14}
Solution Stats
Problem Comments
-
2 Comments
Thomas Pursche
on 13 Mar 2021
It is pretty strange that some solutions do not work even if they are equal
storedvars = fieldnames(S)
FirstVarName = storedvars{1:end}
FirstVarContent = S.(FirstVarName)
c = {storedvars,FirstVarContent}
akihisa yorozu
on 21 Aug 2021
I understand how the cell displayed.
Solution Comments
Show commentsProblem Recent Solvers2050
Suggested Problems
-
Which values occur exactly three times?
5133 Solvers
-
4405 Solvers
-
Back to basics 11 - Max Integer
787 Solvers
-
Set some matrix elements to zero
542 Solvers
-
713 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!