MATLAB Answers

Creating a random matrix with specific values?

4 views (last 30 days)
Anum Ahmed
Anum Ahmed on 20 Feb 2020
Answered: Guillaume on 20 Feb 2020
Hello,
Can someone guide me how to generate a random matrix in Matlab with only specific values in it.
For example, lets say I need a 1*100 element array with values only 0,90,180 in it. How can I do it using Matlab.
Many Thanks

  0 Comments

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 20 Feb 2020
valueset = [0, 90, 180];
desiredsize = [1, 100];
desiredmatrix = valueset(randi(numel(valueset), desiredsize))

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags