Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you load a matrix in from a file in octave?

I loaded an 8bit grayscale image into octave with imread, then I saved it in ascii format and got a giant list of all of it's values. Then I dithered it with a 2x2 matrix in Java and printed out a list of each dithered matrix all on one line.

If the matrix for a pixel in my program turns out to be this:

0 2
3 1

Then the output that my program generates looks like:

0 2 3 1

Then I have all of the matrices for each pixel in that format all on one line. How can I load this into octave to see the final dithered image?

I was messing around with octave and created a simple matrix like the first one I showed and saved that to a file, then I was able to put it all on one line and load it up again just fine. I tried to then replace the matrix in that file with the matrix my program generated, but octave doesn't seem to be loading that in. The matrix it tried to load it to doesn't get changed at all.

like image 406
zak Avatar asked Aug 10 '11 19:08

zak


1 Answers

I dont think I fully understood your question, but if you are having trouble interacting with the file system, I suggest using the functions dlmread and dlmwrite.

The follow code should provide an example to get you started:

%Random 4 by 4 matrix
M = rand(4,4) 

%Write matrix to file system
dlmwrite("filename.txt",M);

%Read it back and store in an other variable
M2 = dlmread("filename.txt")
like image 194
Vidar Avatar answered Oct 19 '22 11:10

Vidar