generate function to print out a random number using different input arguments? - Homework

5 ビュー (過去 30 日間)
Nora
Nora 2013 年 11 月 2 日
コメント済み: sixwwwwww 2013 年 11 月 2 日
Write a function that will print out a random float number:
If no input arguments are passed it will print a random number from 0 to 1
If one input argument is passed then that argument is the max and the random number will be from zero to max
If two arguments are passed, then they represent the min and max for the random number
This is what I have so far:
function [num] ranum( a,b )
fprintf('There is/are %d input argument.\n', nargin);
for i=1:nargin-1
if i == 0
num = rand(1);
end
end
I am not sure how to make the input arguments min and max for when the input is the other two conditions.
  1 件のコメント
sixwwwwww
sixwwwwww 2013 年 11 月 2 日
What you will do if user don't input a or b? then how you will check the condition?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by