Random number selector from double
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Star Strider
2016-1-24
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 个评论
Walter Roberson
2016-1-24
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);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!