Why does any error appear according to complex of a function?

for i=1:numel(xSMp)
ySMp(i)=SMp(xSMp(i));
end
In an assignment A(I) = B, the number of elements in B and I must be the same. This error message appears if the function SMp(x) is complex. In other applications, I have used the same, and these have worked good

5 comentarios

Please post some example data, which reproduce the problem.
Terman Frometa-Castillo
Terman Frometa-Castillo el 18 de Jun. de 2018
Editada: Jan el 19 de Jun. de 2018
The SMp is a function of 2 steps with their powers. I did the test simplifying this function as SMp=0, and the problem disappeared.
function SMp=SMp(x)
global PXmin Xmin Xmax ML p1 p2 Max
SMp=0;
if ((x>=Xmin) && (x<=ML))
SMp = power((x-PXmin)/(ML-PXmin),p1)*Max;
end
if ((x>ML) && (x<=Xmax))
SMp = power((Xmax-x)/(Xmax-ML),p2)*Max;
end
Even I have used in other applications with simpler fucntion, like LQ S(d) model of radibiology, and this problem has not appeared
We still cannot reproduce the problem due to missing inputs and global variables. I guess, that the function does not reply a scalar, but this is not a problem of the complex values.
I have used as global variables to PXmin, Xmin, Xmax, ML, p1, p2 and Max. It is attached my last version of my MatLab application aimed to make a manual fix with the SMp(x) to a data
Global variables are a very bad programming practice, which makes it hard to debug. 1. Avoid globals. 2. Use the debugger to step through your code line by line to find out, what's going on.

Iniciar sesión para comentar.

Respuestas (2)

Guillaume
Guillaume el 19 de Jun. de 2018
global variables are a major source of bugs and it is very hard to track who creates or modify them. Avoid global variables.
Your SMp function uses a global variable called Max (bad name as well, too close to the max function). I cannot see any function in your GUI that actually assigns a value to that global. I would wager that Max is a vector that has been set at some point and forgotten.
Note that there is a Max_Callback function that sets a value to a Max variable but since that Max is not declared global, that value is forgotten as soon as the callback finishes.
In any case, the best thing to do is to put a breakpoint on line 220 of your SMP function and look at the values of your global variables. One of them must be a vector for you to get your error.
Terman Frometa-Castillo
Terman Frometa-Castillo el 19 de Jun. de 2018
Dear Prof. Guillaume,
Thank you. For eliminating the error, it was essential declaring global Max (I will rename it as MaxSMp) in the Max_Callback function.
The SMpx MatLab application is a complement of the attached file, a manuscript submitted to an respectable journal. The SMp(x) could be called "universal" probabilistic distribution (More information in the attachment)
I hope the SMp(x) will be included in the MatLab function list. It was suggested by me to the Prof. Chen Lin (Manager, MATLAB Central Community)
Best regards,
Terman Frometa-Castillo

Categorías

Etiquetas

Preguntada:

el 18 de Jun. de 2018

Respondida:

el 19 de Jun. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by