Execution of code ends prematurely

3 Ansichten (letzte 30 Tage)
Kyle
Kyle am 12 Mär. 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

Akzeptierte Antwort

Kyle
Kyle am 12 Mär. 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.

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 12 Mär. 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 am 12 Mär. 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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by