Errors when randomizing Hexagonal Grid

1 view (last 30 days)
Lawrence Cheng
Lawrence Cheng on 24 Jun 2015
Commented: Lawrence Cheng on 26 Jun 2015
Hi Everyone,
I am currently developing a program that generates a grid of regular hexagons, which I have been able to do
However, I am trying to make it so when a certain percentage is entered(third parameter in function), it will randomly delete that percentage of hexagon sides randomly in the figure that appears. However, I have been using the function randperm to generate random numbers corresponding to the index for which sides/corners to take out, and for some reason when I run it random lines are generated across the screen. Would anyone know why that is?
Thanks!
(the code attached might seem long, but a lot of it just repetitive)
  7 Comments
Mike Garrity
Mike Garrity on 25 Jun 2015
"For instance, the snippet you posted chooses the indexes from 1 to k/2 in the random array of sample, and thus the arrays a and b would have those specific elements set randomly to NaN."
Yes, but sample is bigger than a and b. This means that the a & b arrays get stretched to the size of the sample array. When this happens, any values you haven't specified get filled with 0's. I think that these zeros are what you're seeing.
You can see the pattern in this simple example:
rng(0)
a = 1:7
a(randi(100,[1 5])) = nan
The first disp shows a being a 1x7, but the second disp shows it being big enough to hold the last nan. But it got padded with a lot of zeros.
Lawrence Cheng
Lawrence Cheng on 26 Jun 2015
Ok, I will look into that.
Thank you for your help!

Sign in to comment.

Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!