extract elements and build the remain vector
古いコメントを表示
Hello Community,
i need your help.
A vector v has 128 elements with random numbers.
The elements of index 1 21 31 41 should be etracted, and saved as vector a.
the remain elements of vector v should be saved as vector b.
my version consist two for loops which is in deed a bad solution for large vectors.
PS: the vectors are not constant.
maybe someone could finish the algorithm:
v = 1:128;
a = v([1 21 31 41]);
採用された回答
その他の回答 (1 件)
David Hill
2020 年 12 月 21 日
a=v([1 21 31 41]);
b=v([2:20,22:30,32:40,42:end]);
5 件のコメント
David Hill
2020 年 12 月 21 日
Depending on what random numbers you want, use rand() or randi() functions (assuming uniform distribution)
v=A*rand(1,128)-B;%generates random numbers between -B:A-B
Marko
2020 年 12 月 21 日
David Hill
2020 年 12 月 21 日
b=v(~ismember(v,a));
Marko
2020 年 12 月 21 日
カテゴリ
ヘルプ センター および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!