简体   繁体   English

如何从八度音程的文件中加载矩阵?

[英]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.我使用 imread 将 8 位灰度图像加载到 octave 中,然后将其保存为 ascii 格式,并获得了所有值的巨大列表。 Then I dithered it with a 2x2 matrix in Java and printed out a list of each dithered matrix all on one line.然后我用 Java 中的 2x2 矩阵对其进行抖动,并在一行上打印出每个抖动矩阵的列表。

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:然后我的程序生成的 output 看起来像:

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.然后我尝试用我的程序生成的矩阵替换该文件中的矩阵,但 octave 似乎没有加载它。它试图加载它的矩阵根本没有改变。

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.我认为我没有完全理解您的问题,但如果您在与文件系统交互时遇到问题,我建议使用函数 dlmread 和 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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM