How to plot values in a grid manner so as to form an image?

4 views (last 30 days)
I am writing a function which read data from a file having the following dimension [105 1 107]. Now I want to plot the data(which is in the form of a single column] in a manner such that it creates an image with dimensions [105 X 107]. I have written the following function, but all I get is a blue image, whereas I should get an image with different colors based on the values present at x,y co-ordinate in the mzSpecificData. Can anyone please let me know what is going wrong?
[x,temp,y]=size(mzSpecificData)
for yLoop = 1:y
for xLoop = 1:x
image(mzSpecificData(xLoop,temp,yLoop))
end
end
here; max value of x = 105, value of temp = 1 (which is a single constant value) max value of y = 107
  2 Comments
Image Analyst
Image Analyst on 1 May 2013
What does this mean: "plot the data(which is in the form of a single column] in a manner such that it creates an image with dimensions [105 X 107]" Do you want to plot the values of one of the 107 columns as a line chart, or do you want to take that y-z plane of your image and display it as a 2D gray scale image? What you said is ambiguous. What do you want to do: plot or display?
Novice Geek
Novice Geek on 6 May 2013
Here I wish to "display" my data in the form a 2D image which has the dimensions [105 X 107]. Thats the reason why I used the xLoop and the yLoop which which ask as co-ordinates (xLoop,yLoop) to display data in the form of a color at a specific co-ordinate. I hope I am able to make the problem understood. Thank you

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 6 May 2013
Purva: Your image has 1 for the second dimension (the x or column dimension). That means that it is basically a slice in the y-z plane, with the column being 1 because you have only 1 for that dimension. You can use squeeze to turn this y-z plane into a normal, ordinary grayscale image. You can then display the image as a whole by using image() or imshow().
What your code did was to extract out just one pixel - the pixel at row = xLoop, column = 1, and z=yLoop - and then display just this one single pixel as the whole image. So I'm sure you didn't see anything except just one single square of one intensity, which is just the one pixel.
I hope that explains it better. To see your image you should be able to just do
grayImage = squeeze(mzSpecificData);
imshow(grayImage, []);
There is no loop or anything anymore - that is the entire code.

More Answers (1)

Anand
Anand on 1 May 2013
Try this:
im = squeeze(mzSpecificData);
image(im); %or imshow(im);
  4 Comments
Novice Geek
Novice Geek on 6 May 2013
I know that the loop which I have applied is working I checked and found that the value at a specific co-ordinate (xLoop,yLoop) is correct as well. I now just need to display all these values in an image form. This is where I am stuck.
Novice Geek
Novice Geek on 6 May 2013
But, without a loop how would the function take the next value/ or go to the next co-ordinate. When I used imshow(), I got an image with one pixel after iterating through both the loop 105 X 107 times. Is the image for every pixel overlapping the previous one?

Sign in to comment.

Categories

Find more on Image Processing Toolbox 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!