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 个评论
Jan
2018-6-18
Please post some example data, which reproduce the problem.
Terman Frometa-Castillo
2018-6-18
编辑:Jan
2018-6-19
Jan
2018-6-19
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.
Terman Frometa-Castillo
2018-6-19
Jan
2018-6-19
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.
回答(2 个)
Guillaume
2018-6-19
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!