Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

could anyone help me to solve the issue.

조회 수: 1 (최근 30일)
Prabha Kumaresan
Prabha Kumaresan 2018년 1월 26일
편집: Stephen23 2018년 1월 26일
If i run the following code:
a=0.01
b=0.09
r = 2; c = 10;
[x,v] = randfixedsum(r*c,a,b,0.35);
-------------calling function----------
function [x,v] = randfixedsum(r*c,a,b,0.35)
y = reshape(x,r,c)
v=sum(y(:))
end
I am getting Error in [x,v] = randfixedsum(r*c,a,b,0.35);
Could anyone help me to solve it.
  댓글 수: 2
KSSV
KSSV 2018년 1월 26일
편집: KSSV 2018년 1월 26일
Prabha Kumaresan Yoiu have asked 173 questions so far....and still you have not learned any basics of MATLAB. I feel sorry to say this. You are not at all reading documentation and asking questions in the blog, some one gives some code...you come with slight meaning less changes and even without trying/ reading, you post the same error. This is ridiculous. YOu see the code, you have given:
1. A number cannot be input inside function. You are inputting a number 0.35 inside the function.
2. YOu are trying to reshape x inside the function, this variable is not at all defined to the function.
How you expect us, to solve your problem with lots of typo errors? For the first time we can...but not for the 173rd time. Please be careful while asking questions. And I strongly advice you to read the basics of MATLAB, which are very easy.
Stephen23
Stephen23 2018년 1월 26일
편집: Stephen23 2018년 1월 26일
Original question and (working but not accepted) answer:
@Prabha Kumaresan: why are you wasting your time?

답변 (2개)

KSSV
KSSV 2018년 1월 26일
편집: KSSV 2018년 1월 26일
function myfunction()
r = 2; c = 10;
x = rand(1,2*10) ;
[x,v] = randfixedsum(x,r,c);
end
% -------------calling function----------
function [y,v] = randfixedsum(x,r,c)
y = reshape(x,r,c)
v=sum(y(:))
end
I am surprised...what you are trying to achieve......whether you reshape and do sum on x or directly do sum on x, the answer will be the same.
  댓글 수: 1
Prabha Kumaresan
Prabha Kumaresan 2018년 1월 26일
Actually I want to generate a matrix of random size within the interval [0.01,0.09] such that the sum of the matrix should be 0.35

Walter Roberson
Walter Roberson 2018년 1월 26일
function x = myfunction()
r = 2; c = 10;
x = my_randfixedsum(r,c);
end
function y = my_randfixedsum(r,c)
a = 0.01;
b = 0.09;
s = 0.35;
n = r * c;
m = 1;
if n * a > s || n * b < s
error('Cannot create a sum of %f by adding together %d x %d numbers in the range %f to %f', s, r, c, a, b);
end
randomvec = randfixedsum(n, m, s, a, b);
y = reshape(randomvec, r, c);
end
... just as I told you to do before.
  댓글 수: 2
Prabha Kumaresan
Prabha Kumaresan 2018년 1월 26일
when i run the above code i am getting Error: File: one.m Line: 3 Column: 1 Function definitions are not permitted in this context.
Walter Roberson
Walter Roberson 2018년 1월 26일
Use the files I have attached. Do not insert any code at the top of either of them. You can have your one.m call myfunction() but do not store these functions in one.m .

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by