Creating matrix with different elements
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
M.R. Ebrahimi
le 12 Nov 2020
Commenté : Ameer Hamza
le 12 Nov 2020
Hi
I have to create a 3 * 4 matrix whose elements are between 3 and 8, but the element of each row will be different. How can I creat it?
0 commentaires
Réponse acceptée
Ameer Hamza
le 12 Nov 2020
Modifié(e) : Ameer Hamza
le 12 Nov 2020
This is one way
lb = 3;
ub = 8;
M = rand(3,4);
for i = 1:size(M,1)
M(i,:) = randperm(ub-lb+1, size(M,2))+lb-1;
end
Result
>> M
M =
4 5 8 6
3 6 7 8
7 3 6 8
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays 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!