Why is my function generating a vector? Please help?
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to create a function that does the following:
"The function lastname_lab4_tracker generates the increment to be added takes as input a scalar value and
(i) multiplies it by a random number between -.05 and .05
(ii) then adds another random number also between -.05 and .05 and returns the new scalar number
Here is what I have:
function [a,b]=katz_lab4_tracker(x)
a=randi([1,100])*(x);
b=a+x;
end
In the command window I type this: [a,b]=katz_lab4_tracker(rand([-1,1])/(2))
And it returns this:
a=
0×1 empty double column vector
b =
0×1 empty double column vector
What's the deal here? How can I fix this?
Than you for your help!
댓글 수: 0
답변 (1개)
James Tursa
2019년 11월 6일
A uniform random number between a and b is:
u = a + rand*(b-a)
Generate two of these with a = -0.05 and b = 0.05 and then do the math as outlined in your instructions. Your function will only be returning one value, not two.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!