The meaning and function of codes on programming

1 回表示 (過去 30 日間)
Shuoze Xu
Shuoze Xu 2022 年 3 月 25 日
コメント済み: Shuoze Xu 2022 年 3 月 25 日
Hi.
i learned a method which can ask user for a word and output a random permutation.
But professor showed a kind of method i cannot full undertand.
Here is the code.
% ask user for a word and output a random permutation
% get word
word = input("Enter a word:",'s');
% generate a permutation
permutations = perms(word); % can be used on characters
% pick a randow index
max_choice = size(permutations,1);
choice = randi([1 max_choice]);
perm = permutations(choice,:);
% output
fprintf("%s\n",perm);
what is the meaning of size(permutataions,1), and why let choice is equal to the randi([1 max_choice])
Thank you for your help
  1 件のコメント
Shuoze Xu
Shuoze Xu 2022 年 3 月 25 日
sorry.
i mean what is the purpose of size(permutataions,1),i check the meaing of size() on documents.

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

採用された回答

Mohammed Hamaidi
Mohammed Hamaidi 2022 年 3 月 25 日
size(permutataions,1)
It just compute the number of ppossible permutations.
randi([1 max_choice])
is a random choise the get a permutation
  1 件のコメント
Shuoze Xu
Shuoze Xu 2022 年 3 月 25 日
I got it, thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品


リリース

R2021b

Translated by