Filter löschen
Filter löschen

Could anyone help me to solve the issue in the following code

1 Ansicht (letzte 30 Tage)
Prabha Kumaresan
Prabha Kumaresan am 26 Jan. 2018
Bearbeitet: Jan am 26 Jan. 2018
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 Kommentare
Stephen23
Stephen23 am 26 Jan. 2018
Bearbeitet: Stephen23 am 26 Jan. 2018
@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
Jan am 26 Jan. 2018
Bearbeitet: Jan am 26 Jan. 2018
@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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Torsten
Torsten am 26 Jan. 2018
Bearbeitet: Torsten am 26 Jan. 2018
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 Kommentare
Prabha Kumaresan
Prabha Kumaresan am 26 Jan. 2018
I am sorry for not accepting your answer.could you tell me where I need to accept your answer.
Jan
Jan am 26 Jan. 2018
Bearbeitet: Jan am 26 Jan. 2018
@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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Computations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by