# Random number selector from double

1 visualizzazione (ultimi 30 giorni)
jgillis16 il 24 Gen 2016
Commentato: Walter Roberson il 24 Gen 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?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Star Strider il 24 Gen 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 CommentiMostra NessunoNascondi Nessuno
jgillis16 il 24 Gen 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 il 24 Gen 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);

Accedi per commentare.

### Categorie

Scopri di più su Annotations in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by