Question: Use the Programming Language ---- > MATLAB Write a function with persistent variables currentLocationX and currentLocationY that store an object's location. Each call to the
Use the Programming Language ---- > MATLAB


Write a function with persistent variables currentLocationX and currentLocationY that store an object's location. Each call to the furiction adds deltaXCoord to currentLocationX and adds deltaYCoord to currentLocationY. Assume a starting lccation of 0 for currentLocationX and currentLocationY Your Function Save C Reset MAILAB Documentation 1 function [endl ocationx, endl ocatinny]ndatel ncation(deltaxcnnrd, deltaYcoord) 21% dellaxcoord; Move objecl along x axis % deltavcnnrd: Move object along y axis Declare a persistent variable rurrenti ocation % Declare ia persislenl variable uurrenLLocalionY % If curren!LUCdLionx is emply, assign currenlLocalionx wilh delLaxCoor otherwise, add del taxcoord to current location currenlloaiox- dellaxCourd % If currenLLUCdLiorIY is emply, assigi currenlLocalionY wilh dellayCoor otherwise, add del tavcoord to current locationY currernlLocaliuny -dellaYCourd; ekLocalionx - currenocaiox; endlocationY-currentl oratinnY; end Code to call your function C Resel edLocatix, endocationy UpdteLocation(, s) endLocationX, endLocationY] - UpdateLocation(2, 3) Write a function with persistent variables currentLocationX and currentLocationY that store an object's location. Each call to the furiction adds deltaXCoord to currentLocationX and adds deltaYCoord to currentLocationY. Assume a starting lccation of 0 for currentLocationX and currentLocationY Your Function Save C Reset MAILAB Documentation 1 function [endl ocationx, endl ocatinny]ndatel ncation(deltaxcnnrd, deltaYcoord) 21% dellaxcoord; Move objecl along x axis % deltavcnnrd: Move object along y axis Declare a persistent variable rurrenti ocation % Declare ia persislenl variable uurrenLLocalionY % If curren!LUCdLionx is emply, assign currenlLocalionx wilh delLaxCoor otherwise, add del taxcoord to current location currenlloaiox- dellaxCourd % If currenLLUCdLiorIY is emply, assigi currenlLocalionY wilh dellayCoor otherwise, add del tavcoord to current locationY currernlLocaliuny -dellaYCourd; ekLocalionx - currenocaiox; endlocationY-currentl oratinnY; end Code to call your function C Resel edLocatix, endocationy UpdteLocation(, s) endLocationX, endLocationY] - UpdateLocation(2, 3)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
