Effacer les filtres
Effacer les filtres

Creating a 15x15 matrix with certain specifications

3 vues (au cours des 30 derniers jours)
nick
nick le 11 Mar 2016
Commenté : Star Strider le 11 Mar 2016
Hello everyone,
I am having trouble constructing a 15x15 matrix with the following specifications:
- it should only contain three numbers (0, 1, 2)
- there should be 110 0s (48.89% are zeros)
- there should be 110 1s (48.89% are ones)
- there should be 5 2s (2.22% are twos)
Any hints and explanations are greatly appreciated

Réponse acceptée

Star Strider
Star Strider le 11 Mar 2016
You didn’t say if you wanted it to be random or non-random.
I would create the initial vector as:
v = [zeros(1, 110) ones(1, 110) 2*ones(1,5)];
then for a non-random matrix, just use the reshape function, and for a random matrix, use the randperm function first, then reshape.
  2 commentaires
nick
nick le 11 Mar 2016
Thanks! I was looking for a random matrix, so randperm and reshape worked great!
Star Strider
Star Strider le 11 Mar 2016
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by