error in concatenating cells

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 Commento

Stephen23
Stephen23 il 23 Apr 2024
Modificato: Stephen23 il 23 Apr 2024
"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.

Accedi per commentare.

Risposte (1)

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 Commenti

ET
ET il 23 Apr 2024
Thanks, Walter, it's strange that while ftData728178E.trial looks normal, it turns into nan after converted into matrix.
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")

Accedi per commentare.

Categorie

Prodotti

Release

R2023a

Richiesto:

ET
il 22 Apr 2024

Commentato:

il 23 Apr 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by