error in concatenating cells
2 ビュー (過去 30 日間)
古いコメントを表示
Hello Dear,
I have 1x50 cell (ftData728178E.trial) in a struct. Each cell has a 192x2301 double. After I concatenate the cell to make a matrix of 192x2301x50, the matrix turns into nan. I wonder why it is and what the correct way to turn cells into a matrix. Thanks,
ET
ft_epoch = cat(3, ftData728178E.trial{:});
1 件のコメント
Stephen23
2024 年 4 月 23 日
編集済み: Stephen23
2024 年 4 月 23 日
"error in concatenating cells"
You are not getting any error. When an error is thrown an error message is displayed and code evaluation stops.
" After I concatenate the cell to make a matrix of 192x2301x50"
You are not concatenating cell arrays. You are confusing the cell array itself with the content of the cell array.
"I wonder why it is and what the correct way to turn cells into a matrix."
It is not possible to "turn" a cell array into a numeric matrix, the concept is basically meaningless. Of course you can easily concatenate the content of cell arrays (assuming compatible sizes and types), using e.g. CELL2MAT or CAT or HORZCAT or VERTCAT or the concatenation operator (concatenation together a comma-separated list).
What you showed in your question:
ft_epoch = cat(3, ftData728178E.trial{:});
What your screenshot shows:
ft_epoch = cell2mat(reshape(ftData728178E.trial, 1 ,1 []));
mean(ft_epoch(1,:,:),3)
Most likely your data have some missing values (e.g. NaN) and you have not checked your data thoroughly.
Upload your data in a MAT file by clicking the paperclip button.
回答 (1 件)
Walter Roberson
2024 年 4 月 23 日
ft_epoch = cell2mat(reshape(ftData728178E.trial, 1, 1, []));
However, if what you are already doing creates NaN then it means that the doubles are already NaN, and in that case the cell2mat approach will not help.
2 件のコメント
Walter Roberson
2024 年 4 月 23 日
It shows NaN on the mean(). By default mean() includes NaN values, so if there is a NaN anywhere in the data the result for that page would be NaN.
mean(ft_epoch(1,:,:), 3, "omitmissing")
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!