필터 지우기
필터 지우기

The meaning and function of codes on programming

조회 수: 3 (최근 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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by