Converting cell of numbers to double
56 ビュー (過去 30 日間)
古いコメントを表示
Hi. How do I convert a cell of numbers from cell to double? I looked up the previously asked questions but they mostly involved strings and I have numbers. I didn't post any code, I just want to know if there's any way of doing it if you have a cell class with mutiple matrices in it. How can I also store a cell class in a structure array where each "f1" and "f2" will be the field?
This is what I am having
fie =
2×2 cell array
{["f1"]} {3×7 cell}
{["f2"]} {4×7 cell}
This is what I want
fie =
2×2 cell array
{["f1"]} {3×7 double}
{["f2"]} {4×7 double}
1 件のコメント
Stephen23
2022 年 5 月 27 日
Why fix this problem later, when you could fix it when you import the data?:
採用された回答
Steven Lord
2022 年 5 月 27 日
If the cells in that cell array in the upper-right cell of your outer cell array can be concatenated to form a matrix you could use cell2mat.
C = mat2cell(reshape(1:21, 3, 7), ones(3, 1), [2, ones(1, 5)]) % Making sample data
A = {'abc', C}
B = cell2mat(A{1, 2})
A{1, 2} = B
This wouldn't work if C is not of a form that can be combined together into a matrix, like if the contents of the cells in C don't have compatible numbers of rows and/or columns.
D = {[1 2], 3; [4 5 6], 7} % Can't have a matrix whose rows have different numbers of columns
cell2mat(D)
4 件のコメント
Steven Lord
2022 年 5 月 27 日
q = reshape(1:21, 3, 7)
mystruct.A = q
y = mystruct.A
check = isequal(q, y) % true
その他の回答 (1 件)
参考
カテゴリ
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!