필터 지우기
필터 지우기

fprintf nested cells in matlab

조회 수: 2 (최근 30일)
ZK
ZK 2013년 1월 21일
Hi.
I have the following:
A<3x1 cell>
where cells are arranged in column:
.<1x15 cell>
.<1x15 cell>
.<1x15 cell>
I would like to fprintf content of nested cells with spaces before numbers and with 15 numbers in each row.
Whats more can it be an universal funtion, that could work even when number of cells would be different like:
A<6x1 cell>
.<1x15 cell>
.<1x15 cell>
.<1x15 cell>
.<1x15 cell>
.<1x15 cell>
.<1x13 cell>
Cells content random numbers in format x.xxx Thank You
  댓글 수: 1
Jan
Jan 2013년 1월 21일
Please post valid Matlab syntax. Neither "A<3x1 cell>" not ".<1x15 cell>" is a standard notation. Using Matlab syntax would have the enormous advanatge, that it is clear, easy to read, the common language in this forum and that it can be used directly by copy&paste to test the suggestions.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2013년 1월 21일
편집: Jan 2013년 1월 21일
function PrintNestedCell(fid, C)
for iC = 1:numel(C)
aC = C{iC};
if iscell(aC)
PrintNestedCell(fid, aC);
elseif ischar(aC)
fprintf('%s', aC);
elseif isnumeric(aC)
fprintf('%g ', aC);
else
error('Class not handled: [%s]', class(aC));
end
end
This is a general idea only. I leave adding spaces and other formatting ideas up to you.
  댓글 수: 1
ZK
ZK 2013년 1월 22일
Thank you for answer. I am working on something simpler, but I am a long way from a good efect, fighting with regexp function, in this line.
fprintf(fid, '%s\n', [ (cell2mat(cellfun(@cell2mat, A, 'UniformOutput', false)'))]);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by