Add Consecutive Numbers sent to a Matrix in a Matlab Function
    5 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Vance Blake
 am 6 Mai 2020
  
    
    
    
    
    Bearbeitet: James Tursa
      
      
 am 6 Mai 2020
            Hello, I am writing a function that adds the second value sent to a matrix to the first, the thrid number to the sum of the first two numbers, the fourth number to the sum of the first three...and so on till the last value is added to the sum of all previous values. Any help is greatly apprieciated
function [travel_dist] = DeltaDistance(xB_1) 
       sumxB = xB_1(1) + xB_1(2) 
       travel_dist = deltaX_s-sumxB
    end
0 Kommentare
Akzeptierte Antwort
  James Tursa
      
      
 am 6 Mai 2020
        
      Bearbeitet: James Tursa
      
      
 am 6 Mai 2020
  
      Sounds like maybe you want persistent variable behavior. E.g.,
function travel_dist = DeltaDistance(x)
persistent y
if( isempty(y) )
    y = x;
else
    y = y + x;
end
travel_dist = y;
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Linear Algebra 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!

