Could anyone help me to solve the issue in the following code
2 次查看(过去 30 天)
显示 更早的评论
I have run the following code:
one.m in one script
r = 2
c = 10
[x,v] = randfixedsum(r*c,1,0.35,0.01,0.09)
y = reshape(x,r,c)
sum(y(:))
------------------
In another script
function x = myfunction()
r = 2
c = 10
x = my_randfixedsum(r,c)
end
--------------------------------
In another script
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
when i run the code it works. but when i change the value of r=4 it results in Error using randfixedsum (line 46) Inequalities n*a <= s <= n*b and a < b must hold.
Error in one (line 6) [x,v] = randfixedsum(r*c,1,0.35,0.01,0.09). could you please help me on it. Could anyone help me to fix it.
2 个评论
Stephen23
2018-1-26
编辑:Stephen23
2018-1-26
@Prabha Kumaresan: why did you copy the code and help I gave in my answer ... yet accepted a different (useless) answer and did not even give a single word of thanks for me helping you?:
Do you imagine that it is okay to take my knowledge andefforts and use it without thanking or acknowledging my (volunteered) time helping you? Taking someone's idea without acknowledgement is called plagiarism.
Jan
2018-1-26
编辑:Jan
2018-1-26
@Stephen: Prabha has a hard time to use Matlab and this forum. Of course it would be better, if Prabha cares about the customs in the forum e.g. by posting 1 thread per problem, answering questions for clarifications and carefully accepting the answer, which solves the problem. But as long as this is not the case, I'm sure it is the best not to take it personally.
采纳的回答
Torsten
2018-1-26
编辑:Torsten
2018-1-26
If you choose 40 numbers from the interval [0.01:0.09], they will at least sum to 40*0.01=0.4. But you chose the sum to be 0.35. That's not possible.
Best wishes
Torsten.
7 个评论
Jan
2018-1-26
编辑:Jan
2018-1-26
@Prabha: You have accepted another answer in this thread: https://www.mathworks.com/matlabcentral/answers/378681-could-anyone-help-me-to-fix-the-issue. But to be exact: You do not need to accept another answer. I would have selected Stephen's answer, if this is my thread - but it is yours.
It is irritating, that you accept an answer as solution, which is not working reliably, and use the code of another solution in a following question. While you can accept one answer only (but change your decision later), you can vote for good answers also and the old "thank you" is useful in addition.
But discussions about accepting answers are irritating also. They have never been useful in this forum. Stephen, 3 votes from Walter, Guillaume and me are a statement. Other readers of this thread are not in the danger of choosing the wrong solution, because only your one works reliably.
Prabha, you have been asked several times about the way you participate in this forum, see e.g. https://www.mathworks.com/matlabcentral/answers/378681-could-anyone-help-me-to-fix-the-issue#comment_528707. If you ignore these reactions, your question will be ignored sooner or later also. Please take care to get more focused.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Computations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!