Creating matrix with different elements
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Ameer Hamza
2020-11-12
编辑:Ameer Hamza
2020-11-12
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!