Info

This question is closed. Reopen it to edit or answer.

When I read a matrix stored in a text file, the values are shuffled about

1 view (last 30 days)
fid = fopen('mat.txt','r');
matrix = fscanf(fid,'%g',[6 4]);
Could someone explain why this happens? or suggest a better method?
The matrix consists of 1's and 0's

Answers (1)

Image Analyst
Image Analyst on 17 Mar 2015
Try fread() instead of fscanf(). Not sure that's the problem though. Are you sure you're not confusing (x,y) with (row, column)? That's the error most novices make. Remember (row, column) is (y,x) NOT (x,y).
  2 Comments
laurie
laurie on 17 Mar 2015
Matrix in file:
0 1 0 0
1 1 0 0
1 1 1 0
0 1 1 1
0 1 0 1
0 0 0 1
fscanf:
0 0 0 0
1 0 1 1
0 1 1 0
0 1 1 0
1 1 0 0
1 0 1 1
Image Analyst
Image Analyst on 17 Mar 2015
Edited: Image Analyst on 17 Mar 2015
If you're still having a problem, attach the file with the paper clip icon. Or why not use dlmread() with a delimiter of space or tab, whichever it is?

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!