Editing a matrix to a text file

1 次查看(过去 30 天)
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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by