Function requires number as input; I want to enter a variable though!

조회 수: 2 (최근 30일)
Sean Farrell
Sean Farrell 2017년 1월 13일
댓글: Sean Farrell 2017년 1월 15일
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!

답변 (1개)

KSSV
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
Image Analyst 2017년 1월 15일
Like this:
function A = catalyst_dispersion(b)
total = 1
amount = round(b*total);
random = rand(amount, 1);
Sean Farrell
Sean Farrell 2017년 1월 15일
Thank you KSSV and Image Analyst, this is exactly what I was looking for!! I appreciate the help!
Best, Sean

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by