필터 지우기
필터 지우기

error in concatenating cells

조회 수: 2 (최근 30일)
ET
ET 2024년 4월 22일
댓글: Walter Roberson 2024년 4월 23일
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
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
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
ET
ET 2024년 4월 23일
Thanks, Walter, it's strange that while ftData728178E.trial looks normal, it turns into nan after converted into matrix.
Walter Roberson
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by