recalculation with different rsult respect to previous one

2 views (last 30 days)
Dear all.
Can any one help me about my problem in Mathlab code as following? I have obtained a result and drawn a plot . But, the problem is once I want to do, once again, THE SAME calculations with THE SAME INPUT PARAMETERS, I get DIFFERENT plot. It is very strange and confusing.

Answers (1)

Walter Roberson
Walter Roberson on 21 Mar 2023
This can happen for a couple of different reasons:
  • if the calculations involve random numbers. The random number use might not always be obvious: for example although it is not immediately obvious, kmeans() by default uses random initialization of cluster locations;
  • if you have some kind of accumulation of results and your code forgets to explicitly initialize the variables;
  • if your code relies upon expanding an array and your code does not remember to initialize the array. For example if you have code like A(end+1) = calculation; B = sum(A); then if the code does not remember to clear / truncate the array A then the second time you would be calculating based on results stored the first time through.
  5 Comments
Walter Roberson
Walter Roberson on 24 Mar 2023
Edited: Walter Roberson on 24 Mar 2023
You did not send thue() or fib_bin() or rt_coefficient_te() or rt_coefficient_tm()
Saying
in one category you can put A=0; alpha=1.08, beta=1.86
in another category you can put A=0.2, alpha=1.01, beta=1.95
does not give me enough information about how the code should be run, or what should be plotted, or what I should be looking for when you say the second run returns different results.
Saeid Pourmasoud
Saeid Pourmasoud on 25 Mar 2023
Thank you so much. I solved the problem myself.
With the best wishes

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!