7 views (last 30 days)

So here is my problem.

I have two vectors that descibe a plot (a sinusiodal function) and I want to have the discretized matrix of this plot. It means that I want to have a 1 on the curve and 0 everywhere else.

Is this possible ?

Stephan
on 24 Mar 2020

Edited: Stephan
on 24 Mar 2020

x = 0:0.01:6.28;

y = sin(x);

M = ones(size(x,2));

x_int = 1:size(x,2);

y_int = ceil(y * size(y,2)/(abs(min(y))+abs(max(y))) +...

size(y,2)/(abs(min(y))+abs(max(y))));

y_int(y_int>size(M,2)) = y_int(y_int>size(M,2))-1;

for k = 1:size(y,2)

M(y_int(k),x_int(k)) = 0;

end

imshow(M)

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814557

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814557

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814562

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814562

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814567

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814567

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814569

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814569

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814575

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/512622-convert-two-vectors-x-and-y-to-a-square-matrix#comment_814575

Sign in to comment.