Q:

Converting a matrix in a text file to a grayscale image

So I'm a bit confused about something. I created a function in C to calculate some values and store them in a matrix file. This matrix file opens in notepad and contains rows and columns of float values. Anyway, I have seen matrices being displayed as some form of grey scale pixel-like image and was wondering if I can do that in Matlab? I have done research but nowhere seems to actually explain what they are. I'm not really a pro in Matlab as I only did it for a few weeks in one semester but good enough to understand it. Well my question is, does anyone follow what I mean by converting a matrix to a grey scale pixel-like image and if so, how would one implement that in Matlab?

A:

Yes, Matlab can do that in various ways.  I would recommend the imagesc command, which treats each matrix element as an image pixel.  The convenient thing is that it scales the values to the range of the numbers in your matrix, so it doesn't matter what numbers you give it.
You may also want to look at the dlmread function for reading in an ASCII file as a matrix.
Here is a code example to demonstrate how simple it can be.
data = dlmread('myfile.txt')
imagesc(data);

