Function requires number as input; I want to enter a variable though!
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone! So, I am currently working on a code that uses the rand function. I have a variable set to a particular value, and the value changes based on the user's input to the function. I want to use this variable in the rand function. However, when I run the code, an error comes back stating that I can only enter numbers into the rand function, not variables. Any idea how I can get around this?
Thank you in advance!
0 个评论
回答(1 个)
KSSV
2017-1-13
% rand column vectors
col = 3 ;
rand(col,1)
% rand row vectors
row = 4 ;
rand(1,row)
% matrix of rand
rand(row,col)
rand needs only number as input. If you still face problem, show the code how you have called it.
6 个评论
Image Analyst
2017-1-15
Like this:
function A = catalyst_dispersion(b)
total = 1
amount = round(b*total);
random = rand(amount, 1);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!