简体   繁体   English

如何从八度音程矩阵中随机选择n个数字

[英]how to randomly select n numbers from a column of matrix in octave

I am writing a Particle Swarm Optimization program and for that i want to initialize my particles. 我正在编写一个粒子群优化程序,为此我想初始化我的粒子。 I want my particles to be initialized randomly from the column on which i am applying swarm optimization. 我想从我正在应用swarm优化的列中随机初始化我的粒子。 I am doing the program in Octave. 我正在Octave做这个程序。 I tried looking up for related commands but coundt find one. 我试着查找相关的命令,但是找到了一个。 I want the answer in a matrix form. 我希望以矩阵形式给出答案。
Help is appreciated. 感谢帮助。
For Ex 对于Ex

733
590
495
479
569
560
305
433
319
244
256
255
398
340


from this i want 5 numbers like 从这个我想要5个数字
305 590 495 244 340
Help is appreciated. 感谢帮助。

X = magic(10);

% pick k random numbers for column n:

k = 4;
n = 3;
X(randi(size(X,1), k, 1), n)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM