Using cellwrite to write matrix to .txt
    4 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I have a 66x23 matrix that has strings in the first row, strings in the first three columns, and then the rest is doubles. The matrix is a cell matrix and thus I decided to give cellwrite a try. The output in the text file does not take into account when the next row begins. Any advice on how I can fix this in the cellwrite.m file or in my code?
It should be noted that the size of the matrix can/probably will change as this is to analyze data that comes in a certain format.
Thanks in advance.
3 件のコメント
  Jan
      
      
 2012 年 5 月 13 日
				I do not want to bother you, but does this mean, that I guessed the correct function? 
回答 (1 件)
  Jan
      
      
 2012 年 5 月 13 日
        I do not want to fix the code of cellwrite. What about a simple Cell2File tool like:
function WriteCell(FID, C)
Sep = ' ';
[m, n] = size(C);
for i = 1:m
  for j = 1:n
    aC = C{i, j};
    if ischar(aC)
      fwrite(FID, aC, 'char');
    elseif isnumeric(aC)
      fprintf(FID, '%g', aC);
    else
      fwrite(FID, '???', 'char');
      warning(['JSim:', mfilename, ':BadDataType'], ...
              ['Class not handled yet: ', class(aC)]);
    end
      if j < n
        fwrite(FID, Sep, 'char');
      else
        fwrite(FID, char(10), 'char');
      end
    end
  end
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Text Files についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!