Asked by Osama Tabbakh
on 23 Feb 2019

I want to transform two vectors (x, y) that describe a straight line in the domain (axis([1e-2 7e-2 1e-2 7e-2])) into a logical matrix.

x = linspace (2e-2,6e-2,20);

y = 4e-2 * ones (1,20);

a = [x' y'];

plot (x,y);

axis([1e-2 7e-2 1e-2 7e-2])

I want to get 100*100 matrix, which describe this plot. For that I can creat zeros matrix and then I have to put the ones in the correct place in this matrix. But I don't know where are the correct places.

Answer by Munish Raj
on 27 Feb 2019

Accepted Answer

Since the line is in the middle of your plot, the row indices of the plot will be the 50th row(middle).

Since the line goes from 0.02 - 0.06 and the axes start from 0.01 and ends at 0.07, your line will start in the 17th position and end at the 83rd position on the x axis.

The following code implements this

im = zeros(100); %Create a 100x100 matrix of zeros

im(50,17:83)=1 % make the necessary elements

I = mat2gray(im);

imshow(I); %Displays the image

Osama Tabbakh
on 27 Feb 2019

But why the image is very small in compare to the one, that i plot?

Munish Raj
on 27 Feb 2019

Hello

use your mouse , and drag the corner of the image window to youmake the image as big as tou want it.

Thank you

Osama Tabbakh
on 27 Feb 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Image Analyst (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/446594-how-to-create-logical-image-from-plot-in-a-given-scale#comment_674345

## Osama Tabbakh (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/446594-how-to-create-logical-image-from-plot-in-a-given-scale#comment_674368

Sign in to comment.