Execution of code ends prematurely

3 views (last 30 days)
Kyle
Kyle on 12 Mar 2011
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

Accepted Answer

Kyle
Kyle on 12 Mar 2011
@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.

More Answers (2)

Walter Roberson
Walter Roberson on 12 Mar 2011
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 on 12 Mar 2011
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.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!