Creating a random matrix with specific values?

6 vues (au cours des 30 derniers jours)
Anum Ahmed
Anum Ahmed le 20 Fév 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

Réponse acceptée

Guillaume
Guillaume le 20 Fév 2020
valueset = [0, 90, 180];
desiredsize = [1, 100];
desiredmatrix = valueset(randi(numel(valueset), desiredsize))

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by