Borrar filtros
Borrar filtros

The meaning and function of codes on programming

1 visualización (últimos 30 días)
Shuoze Xu
Shuoze Xu el 25 de Mzo. de 2022
Comentada: Shuoze Xu el 25 de Mzo. de 2022
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 comentario
Shuoze Xu
Shuoze Xu el 25 de Mzo. de 2022
sorry.
i mean what is the purpose of size(permutataions,1),i check the meaing of size() on documents.

Iniciar sesión para comentar.

Respuesta aceptada

Mohammed Hamaidi
Mohammed Hamaidi el 25 de Mzo. de 2022
size(permutataions,1)
It just compute the number of ppossible permutations.
randi([1 max_choice])
is a random choise the get a permutation

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by