CREATING a SET of any length at one time

2 ビュー (過去 30 日間)
Shahad Alsubhi
Shahad Alsubhi 2022 年 3 月 20 日
回答済み: Abhishek Chakram 2023 年 10 月 9 日
この 質問 は Dyuman Joshi さんによってフラグが設定されました
how to CREATING a SET of any length at one time?
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 3 月 20 日
What properties does the set have to have? Is it a set of positive integers? Is it a set of double precision numbers? Is it a dense set or a sparse set? Are you willing to impose a maximum set size (because if not then we have to start working on ways to represent arbitrary precision numbers on disk.)

サインインしてコメントする。

回答 (1 件)

Abhishek Chakram
Abhishek Chakram 2023 年 10 月 9 日
Hi Shahad Alsubhi,
It is my understanding that you want to create set of any length at one time. Here are some ways to achieve the same:
  • Using direct assignment: You can create set of any length of your requirement just by assigning them to a variable. Here is an example for the same:
mySet = [1,2,24,2,24,23,4,235,45,4,3,43,4,34,34,3,43,43,2];
  • Using the “randperm” function: The “randperm” function generates a random permutation of integers. You can use it to create a set of unique integers within a specfied range. Here is an example for the same:
n = 10; % Length of the set
mySet = randperm(n);
  • Using the “randi” function: The “randi” function generates random integers from a specified range. You can use it to create a set of random integers of any length. Here is an example for the same:
n = 20; % Length of the set
range = [1, 100]; % Range of integers
mySet = randi(range, 1, n);
  • Using the colon operator: The colon operator (:) allows you to create a set of consecutive numbers. You can specify the starting value, step size, and ending value to create a set of any length. Here is an example for the same:
n = 100; % Length of the set
mySet = 1:n;
You can refer to the following documentation to know more about the functions used:
Best Regards,
Abhishek Chakram

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by