How implement sine wave on zeros array containing only 1 and 0
Show older comments
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)
Walter Roberson
on 14 Sep 2022
0 votes
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
Walter Roberson
on 14 Sep 2022
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.
Walter Roberson
on 14 Sep 2022
Instead of doing the calculations yourself I suggest using rescale() of the sine wave to the height of array
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!