0
votes

I have a {3,1} cell array, each cell contains a vector of (1,81) with numbers from 1 to 9. A simple fprintf function doesn't work with cells, so i made the following code.

    for j = 1:length(CellArray)
            fprintf(fid,formatSpec,CellArray{j});
    end

This works fine, but I want a seperate line for each CellArray.

        formatSpec = '%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i\n'  
%81 integers and a new line  

Something like this doesn't work as well. The next CellArray is just pasted after the last number of the previous one. So a huge line is printed into the text file, instead of 3.

1
Which programming language do you use? - pbaldauf

1 Answers

0
votes

Try to print all cells, then print a newline:

    for j = 1:length(CellArray)
            fprintf(fid," %i",CellArray{j});
    end
    fprintf(fid,"\n");