Using Matlabwrite Function Creates Structure Variable Called Createspacecraft Function Tak Q37087479

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 (20, 15, 80, 65) ans = scalar structure containing the fields: mass20 fuel 15 orbit 80 engine65

>>createSpacecraft

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.