How implement sine wave on zeros array containing only 1 and 0

Hello, I want yo create an array like below containing 1's and 0's. The 1's are for sine wave points. Can anybody help me how can I get this type of array:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0
0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0
1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0

Answers (1)

If you use the Computer Vision Toolbox then you can insertShape into an array. That returns an rgb array so you would binarize it afterwards.

2 Comments

Alternatively, take your sine wave and multiply it by half the height of your array and add half the height and add 1. Round to integer. Now use subs2ind with size of your array, and 1:width as the third parameter, and the calculated values as the second parameter, which will give you linear indices. Set those locations to 1.
Instead of doing the calculations yourself I suggest using rescale() of the sine wave to the height of array

Sign in to comment.

Categories

Products

Release

R2022a

Asked:

on 14 Sep 2022

Commented:

on 14 Sep 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!