Problem with writing a matrix into a text file
Show older comments
Hi!
I did a script for making a 100x100 matrix and tried to convert it into a text file. The code goes lie this:
a=zeros(100,100);
for i=1:100
for j=1:100
a(j,i)=30;
end
end
dlmwrite('grid.txt', a, 'delimiter', '\t')
type grid.txt
The first couple of lines of the text come out okay, but then there are some elements like 3030 or 3 and at the end of the lines some elements are empty or zeros. Also the matrix does not look like 100x100 in the text file, more like 333x30. What is the problem in this?
Thanks
Answers (1)
per isakson
on 11 Oct 2012
Edited: per isakson
on 11 Oct 2012
0 votes
I run your code on R2012a, 64Bit, Win7. It works as expected. I see neither 3 nor 3030.
- Open in Excel produced a 100 row sheet. Last column is CV.
- Open in Matlab editor it looks ok
- Import data to Matlab gives a <100x100 double > array
- type grid.txt gives the expected result in the command window
Did you try to change your tab settings of the editor?
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!