]> Exercises

Exercises

Complete each exercise or answer the question before reviewing the posted solution comments.

  1. Write a script that displays 'You rolled a ' and the first value of randomly generated values between 1 and 6. Hint: Read about the randperm function.

        x = randperm(6);
        disp(['You rolled a ', num2str(x(1))]);

    Did you remember the [ ] brackets and to use the num2str() function to convert the value to a character string?

    The randperm function takes a positive integer N and returns a vector containing the values from 1 to N in a random order. In other words, randperm(N) returns a random permutation of the values from 1 to N.