Execution of code ends prematurely

조회 수: 4 (최근 30일)
Kyle
Kyle 2011년 3월 12일
Hi,
I have a function that is about 100 lines long, but it is not executed after the following block within the function:
k = 1;
coeffs=[];
[m_cutfit2, n_cutfit2] = size(co_c_s_f);
while k <= n_cutfit2
coeffs = vertcat(coeffs, polyfit(q_fitting,co_c_s_f(:,k),9));
k=k+1;
end
%rest of code
No error message or busy signal is given. What is the general cause of this problem, and how may I fix it in this case?
Thanks

채택된 답변

Kyle
Kyle 2011년 3월 12일
@Matt - Thanks for the cleaning up of the concatenation code. I wasn't sure how to do that.
When I cleared all variables and re-ran the script, it worked. Sorry to have wasted your time. I appreciate your help though.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2011년 3월 12일
If the second dimension of co_c_s_f is 0 (empty matrix) then the loop will not be executed because 1 <= 0 is false.
If you are saying that the loop is being executed but somewhere along the way the routine as a whole quits, then have you try commanding
dbstop if error
at the command line, before execution?

Matt Tearle
Matt Tearle 2011년 3월 12일
This isn't the cause of the problem, but first:
n_cutfit2 = size(co...,2);
coeffs = zeros(n_cutfit2,10)
for k = 1:n_cutfit2
coeffs(k,:) = ...
end
Now, do you mean that the code executes up to and including this loop, but the rest of the code just doesn't run? How have you determined this? Have you tried setting a breakpoint at the next line? Without seeing the rest of the code, it's hard to know what might be happening.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by