error of All contents of the input cell array must be of the same data type.
    조회 수: 17 (최근 30일)
  
       이전 댓글 표시
    
cellArray =
    'p4004'
    [4005]
    [4007]
    [4009]
    [4015]
    cellArray      5x1              1202  cell
% when I perform
cellArray=cell2mat(cellArray)
it gives " All contents of the input cell array must be of the same data type." the error.
%I need to perform these transformations to get cell array of strings
cellArray=cell2mat(cellArray)
cellArray=num2str(cellArray)
cellArray=cellstr(cellArray)
댓글 수: 0
채택된 답변
  Azzi Abdelmalek
      
      
 2014년 2월 16일
        
      편집: Azzi Abdelmalek
      
      
 2014년 2월 16일
  
      'p4004' is a string when the other data are double. you can't use cell2mat with mixed data types
If you need to extract a number from 'p4004'
cellArray ={'p4004' [4005] [4007]}
a=cellfun(@num2str,cellArray,'un',0)
b=regexp(a,'\d+(\.)?\d+','match')
c=cellfun(@str2double,b)
댓글 수: 0
추가 답변 (1개)
  Nikola Mirkov
      
 2020년 8월 25일
        Hey Sermet,
Even easier:
cellArray(cellfun(@ischar,cellArray)) = {nan};
cellArray  = cell2mat(cellArray);
Best,
niko
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


