Prev: Juggling with fsolve (or another fsolve problem)
Next: What does it mean for a folder with "@" in front of the name?
From: Nives Fakin on 12 Aug 2010 12:25 the function is supposed to decompose matrix B to two new ones, C_1 and C_2. then, for each of the new matrices checks the condition and decompose if needed. i use n to name the new matrices, but if i define variable n=1 at the beginning of the function, it resets every time back to 1, and i don't know how to define it withot giving it a value. also, i have a problem with deleting the old matrix that i have decomposed beacuse i don't know which one is used of the two. i'm not sure any more why i put clear B, but it helped at the moment :) i'll try to remove it thank you very much
From: Walter Roberson on 12 Aug 2010 15:15
Nives Fakin wrote: > a function i wrote requires defining the variable n, but if i define it > in the begining of the function, since it is a recursion, it changes it > to the old value every time. how to avoid it? please don't resent if it > is a silly question, i'm a beginner with matlab. > > this is the critical loop inside the function "identification" > > for i=1:k > if A(i)>thr > eval(['C_' num2str(n) '=C(1:br1,1:br1)']); > eval(['C_' num2str(n+1) '=C(br1+1:k,br1+1:k)']); Why are you using eval ??? > n=n+2; > clear B; > counter=counter+1; > identification(C(1:br1,1:br1)); > identification(C(br1+1:k,br1+1:k)); > break > elseif i<k > continue > end > end function y = recurseme(x, n) if ~exist('n', 'variable') y = recurseme(x, 0); else n = n + 1; if n <= x y = n * recurseme(x-1, n+1); else y = x-1; end end end And no, I have no idea what that computes -- it's just a sample to show you how you can deal with having an intermediate variable which is not part of the user calling sequence. |