Editing a matrix to a text file

I have a matrix that is saved to a text file. The output of that code is a matrix which looks something like below:
  • 0000000000
  • 0000000000
  • 0000000000
  • 0000000000
How can I create a space between each element so that it looks something like this:
  • 0 0 0 0 0 0 0 0 0 0
  • 0 0 0 0 0 0 0 0 0 0
  • 0 0 0 0 0 0 0 0 0 0
  • 0 0 0 0 0 0 0 0 0 0
The code that I am using is the following:
im1 = imread('im10.png');
bw1 = im2bw(im1, 0.5);
fileID = fopen('exp1.txt','wt'); %open for writing
for i=1:size(bw1,1)
fprintf(fileID,'%d', bw1(i,:))
fprintf(fileID, '\n')
end
fclose(fileID)
The code is used to change a photo to a binary and save it as 1s and 0s. The only thing I would like to do is have one space between each element in each row.
Thank you very much

 Accepted Answer

Can't you just add a space to the fprintf?:
fprintf(fileID,'%d ', bw1(i,:))

More Answers (0)

Categories

Asked:

on 23 Sep 2014

Commented:

on 23 Sep 2014

Community Treasure Hunt

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

Start Hunting!