How do I make an image of numbers using imagesc? Change values in the matrix?
Show older comments
Hello, I am new to MatLab and manipulating matrices.
I have been instructed to make a 2-D matrix 700x400 of any non-zero numbers I want. I have been asked to use [X,Y]=meshgrid(va,vb) where va and vb are vectors (I beleive the purpose of this is so that I can then use the variables X and Y in other functions).
Then I want to make an image of the function using "imagesc" but in greyscale.
Then I want to change the value of the array elements X: 300:310, Y: 40:50 so that they are the same number and thus show up as a spot in the image.
This is what I have so far. I believe the matrix has been created properly but please correct if not. Then when I try to do imagesc, it only lets me put in one variable, X or Y. It id not in greyscale. And then I am not sure how to change values within the array for X and Y.
Thank you so much!
va=1:700;
vb=1:400;
[X,Y] = meshgrid(va,vb);
Accepted Answer
More Answers (1)
Image Analyst
on 21 Feb 2023
Try this:
imshow(yourImage, []); % Display matrix.
axis('on', 'image'); % Show tick marks.
impixelinfo; % Let user mouse around and see RGB values and (x,y) coordinate.
If that doesn't work then explain how you got your matrix. Is it a formula where you used X and Y to compute some surface?
4 Comments
Macy
on 21 Feb 2023
Macy
on 21 Feb 2023
Of course "yourImage" is the matrix you made. You never told me what you're calling it so I just called it yourImage and figured you'd know to replace that variable with the actual name of your image matrix. I guess not, so here is an example with a sample image I made from the two vectors:
columns = 1:700;
rows = 1:400;
[X,Y] = meshgrid(columns, rows);
subplot(2, 2, 1);
imshow(X, [])
title('X', 'fontSize', 20);
subplot(2, 2, 2);
imshow(Y, [])
title('Y', 'fontSize', 20);
% Make an image that is X^2 + y^2, just as an example function.
yourImage = X .^ 2 + Y .^ 2;
subplot(2, 2, 3);
imshow(yourImage, [])
title('X .^ 2 + Y .^ 2', 'fontSize', 20, 'Interpreter','none');
Macy
on 22 Feb 2023
Categories
Find more on Creating and Concatenating Matrices 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!





