convert a cell (Rx1 cell) to a vector (Rx1 double)
2 ビュー (過去 30 日間)
古いコメントを表示
Hi. I want to convert the cell 'rows_check_n' into a vector of type double with the numbers inside the cell.
I tried 'cell2mat' but it is not clear to me why it transforms 270x1 cell into a vector 257x1 double. How can I solve this?
rows_check_n = load("rows_check_n.mat");
rows_check_n = rows_check_n.rows_check_n; % 270x1 cell
rows_check_n_double = cell2mat(rows_check_n); % 257x1 double
0 件のコメント
回答 (2 件)
Walter Roberson
2023 年 12 月 7 日
移動済み: Walter Roberson
2023 年 12 月 7 日
13 entries in the cell are empty.
rows_check_n = load("rows_check_n.mat");
rows_check_n = rows_check_n.rows_check_n; % 270x1 cell
disp(find(cellfun(@isempty, rows_check_n)))
0 件のコメント
Stephen23
2023 年 12 月 8 日
編集済み: Stephen23
2023 年 12 月 8 日
"but it is not clear to me why it transforms 270x1 cell into a vector 257x1 double"
It is easy to check your data (you have been using MATLAB for over three years now, you can do this too):
S = load("rows_check_n.mat");
C = S.rows_check_n % 270x1 cell
X = cellfun(@isscalar,C);
all(X) % are all of them scalar as you believe? (hint: no)
Lets replace the non-scalar elements of C with NaNs, then you get a vector of the same size as C:
V = nan(size(C));
V(X) = [C{X}]
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!