error in concatenating cells
5 次查看(过去 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 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!