Question
Function Name: warriors Inputs: 1. (struct) An 1xN structure array 2. (char) A field name Outputs: 1. (struct) An 1xM updated structure array 2. (char)
Function Name: warriors Inputs: 1. (struct) An 1xN structure array 2. (char) A field name Outputs: 1. (struct) An 1xM updated structure array 2. (char) A descriptive statement about the clan battle Background: While reading everyone's favorite childhood book series about clans of feral cats, Warriors, you realize that the plot is quite difficult to keep up with at times. Rather than simply following the exciting adventures of the protagonist, Firepaw of the ThunderClan, like a casual reader, you decide to go the extra step. Since you are such a dedicated fan of this incredible series, you will write a MATLAB function to track the battles of the clans throughout the saga. Function Description: Write a function that takes in an 1xN structure array and a field name of a statistic that is the most important in a particular battle. Each structure in the array represents a different clan of cats. Based on the values of the field from the given field name (second input) which are guaranteed to be of type double, you will determine which clans battle and who will win. The clan with the highest value in the given field will win in a warrior battle against the clan with the lowest value in the given field. Any intermediary clans will not be affected by the battle. Make the following updates to the structure array based on this battle:
1. The winning clan's structure's value in the field given by the second input should be tripled. 2. The winning clan's structure's value of the Territories field, represented by a cell array of strings, should be updated to include the values of the Territories field in the losing clan's structure. 3. The losing clan's value in the field given by the second input should be set to -1. 4. The losing clan's value for the Territories field should become an empty cell array, {}. 5. Sort the entire array in ascending order based on the values in the field given by the second input. In addition to updating the structure array, the function should also output a descriptive statement in the following format: 'Fearless leader has successfully and gloriously led to victory against .' Continued... Example: >> clans = Name : 'ShadowClan' Leader : 'Brokenstar' Territories : {'northeast marshes'} Strength : 75 Name: 'Thunderclan' Leader: 'Firestar' Territories : {'southeast woodlands'} Strength : 80 >> [updatedClans, result] warriors(clans, 'Strength') updatedClans = Name : 'Shadowclan' Leader : 'Brokenstar' Territories : {} Strength : -1 Name : 'Thunderclan' Leader: 'Firestar' Territories : {'southeast woodlands', 'northeast marshes } Strength : 240 result 'Fearless leader Firestar has successfully and gloriously led Thunderclan to victory against ShadowClan.' Notes: The input structure array is guaranteed to have the following fields: 'Name', 'Leader', and 'Territories'. It is guaranteed that the values in the field given by the second input will be a 1x1 double. It is guaranteed that the value in the Territories field will be a cell array. There will not be any ties.MATLAB problem
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started