如何在rand末尾添加数字 [英] How to add number at the end of rand
本文介绍了如何在rand末尾添加数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我必须生成5行随机数,并且在随机数末尾,我必须在(-1到-9)之间添加一个额外的负数.实数可以帮我吗?下面的代码将创建我需要的所有内容,但是我必须以某种方式将它们组合起来.结果必须为
Hello I have to generate 5 lines of random numbers and at the end of random numbers I have to add one extra negative number from (-1 to -9) I tried strcat and things like that but I couldn't combine negative and real numbers can You help me please? The code below will create everything what I need but I have to somehow combine them. Result has to be for example
1 2 3 4 5 -1
5 8 3 5 9 -2
.
.
.
9 2 4 8 6 -9
for b = 1:9
x = round(rand(1,5)*9);
disp(x)
end
for a = -1:-1:-9
disp (a);
end
推荐答案
[round(rand(9,5) * 9), -(1:9)']
这篇关于如何在rand末尾添加数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文