USING MATLAB…Write a function that creates a structurevariable called createSpacecraft. The function should take fourinputs, a number called mass (in kg), a number called fuel (injoules of energy), a number called orbit (in meters), and a numbercalled engine (in newtons). It should return an output structurecalled spacecraft containing each of those values. Please ensurethat both the function name, AND the names of variables within thespacecraft structure are exactly as instructed
Solution
MATLABFunction:
function spacecraft = createSpacecraft (mass, fuel, orbit,engine)
% Function that creates the spacecraft structure with the givenfields
% Creating SpaceCraft
spacecraft =struct(“mass”,mass,”fuel”,fuel,”orbit”,orbit,”engine”,engine);
end % function end
__________________________________________________________________________________________________
SampleRun:
>>createSpacecraft