Execution of code ends prematurely

4 次查看(过去 30 天)
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