From: Eamonn B on 5 Apr 2010 14:18 Ok I have two function, One does a calculation based on the the Second functions variable depending on the result a value will be assigned to a variable inside function One. But it doesnt update its self and just keeps replacing the value held in the variable. function turn = %%gets points from function 2 does cal if cal is > something turn = [turn 1] else turn = [turn -1] but it does append to its self and just replaces the value anyone know what I am doing wrong?
From: James Tursa on 5 Apr 2010 14:34 "Eamonn B" <pakblue11(a)gmail.com> wrote in message <hpd9gs$aus$1(a)fred.mathworks.com>... > Ok I have two function, One does a calculation based on the the Second functions variable depending on the result a value will be assigned to a variable inside function One. But it doesnt update its self and just keeps replacing the value held in the variable. > > function turn = %%gets points from function 2 > > does cal > > if cal is > something > turn = [turn 1] > > else > turn = [turn -1] > > but it does append to its self and just replaces the value > > anyone know what I am doing wrong? Yes. Your problem is that you didn't post any real m-code for us to look at and debug. James Tursa
From: Eamonn B on 5 Apr 2010 15:32 I have changed some of the code since posting but it still does the samething Function 1 function [turn] = crossTurn(x0,y0,x1,y1,x2,y2) prevPoints = []; cross = ((x2-x0)*(y1-y0))-((x1-x0)*(y2-y0)); if(cross==0) turn = [prevPoints 0]; elseif(cross<0) turn = [prevPoints -1]; elseif(cross>0) turn = [prevPoints 1]; end end %%%%%%%%%%%%%%%%%%%%% Function 2 function convex a = [[5 2 1 4 -1 12 9 13 14]' [6 3 10 3 -5 6 4 4 3]']; % [x] [y] .. .. .. .. for i=3:length(a) . . . uLength = length(upper); turn = crossTurn(upper(uLength-5),upper(uLength-4),upper(uLength-3),upper(uLength-2),upper(uLength-1),upper(uLength)) end end %%%%%%%%%%%%%%%%%%%
From: TideMan on 5 Apr 2010 15:57 On Apr 6, 7:32 am, "Eamonn B" <pakblu...(a)gmail.com> wrote: > I have changed some of the code since posting but it still does the samething > Function 1 > function [turn] = crossTurn(x0,y0,x1,y1,x2,y2) > prevPoints = []; > > cross = ((x2-x0)*(y1-y0))-((x1-x0)*(y2-y0)); > > if(cross==0) > turn = [prevPoints 0]; > > elseif(cross<0) > turn = [prevPoints -1]; > > elseif(cross>0) > turn = [prevPoints 1]; > end > end > > %%%%%%%%%%%%%%%%%%%%% > > Function 2 > function convex > a = [[5 2 1 4 -1 12 9 13 14]' [6 3 10 3 -5 6 4 4 3]']; % [x] [y] > . > . > . > . > for i=3:length(a) > . > . > . > uLength = length(upper); > turn = crossTurn(upper(uLength-5),upper(uLength-4),upper(uLength-3),upper(uLength-2),upper(uLength-1),upper(uLength)) > > end > > end > %%%%%%%%%%%%%%%%%%% But the 2nd function has no output and the index i appears to do nothing. turn is simply overwritten in each loop. You probably need to make turn a vector. BTW, i is a poor choice for index because it resets sqrt(-1).
From: Eamonn B on 5 Apr 2010 16:13 I deleted some of the code in the second function There are two points in upper and i appends the next point to upper. Whats the difference between an array and a vector?
|
Next
|
Last
Pages: 1 2 Prev: howto: Calling MATLAB from C - returning values? Next: Control Theory PID tuning |