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!