Random number selector from double

1 view (last 30 days)
jgillis16
jgillis16 on 24 Jan 2016
Commented: Walter Roberson on 24 Jan 2016
I have drafted the following code:
num_to_fetch = round(66 / 100 * length(FaY3));
your_subset = FaY3(randperm(length(FaY3), num_to_fetch));
your_subsetFas = (your_subset).*(1.46);
where I chose 66% of the data in the double, multiply it by a constant (1.46), then move it into another double. FaY3 actually comes from a 2x43 double defined as FaXY3. What I want to do is modify this code so that whatever 66% of random numbers are selected from FaXY3(2,:), I need the new matrix to also incorporate FaXY3(1,:).
How would I go about doing this?

Answers (1)

Star Strider
Star Strider on 24 Jan 2016
I don’t completely understand what you want with your matrices, but this is one possibility:
D = randi(99, 1 100); % Create Data
I = randperm(100,66); % Indices (66 Unique Values out of 100)
Out = D(I); % Result
I’m not sure what you want to do with your other matrix, but this should get you started.
  2 Comments
jgillis16
jgillis16 on 24 Jan 2016
FaXY3 contains both FaY3 and FaX2. Both of FaY3 and FaX2 create coordinates, so if I have 1 in FaY3 it is only associated to 3.5 in FaX2. But, I'm pulling random numbers solely out of FaY3, so I don't have numbers associated with the numbers coming out of FaY3 to FaX2 and so I lose my 'set' created. How would I pull a random number out of FaY3 and the number associated with the place in the matrix out of FaX2 into a new double?
Hope that makes sense...
Walter Roberson
Walter Roberson on 24 Jan 2016
Either I do not understand your question or you do not understand Star Strider's answer. If you want corresponding elements of FaY3(1,:) and FaY3(2,:) then use that I index Star Strider shows for both of them.
first_var = FaY3(1,I);
second_var = FaY3(2,I);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!