Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

matlab Inputs: 1. (struct) An 1xN structure array 2 (char) A fieid name Outputs:

ID: 3736117 • Letter: M

Question

matlab

Inputs: 1. (struct) An 1xN structure array 2 (char) A fieid name Outputs: (struct) An 1xM updaled strucbure array char) A descriptive statement about the dan battle 2 everyone's favorite childhood book serkes about dans of feral cats Rather than simply While reading anoce you realize that the plot is qute dmcult to keep up with at times. exciting adventures of the protagonist, Firepaw of he ThunderClan, ike a casual crodible reader, you decide to go the extra step Since you are such a dedicated fan of this in senes, you will write a MATLAB function to track the battles of the dans th Function Description: that takes in an 1xN structure anay and a feld name of a statistic thnat is the most important in a particular battle. Each structure in the array represents a diferent clan of cats. Based on the values quaranteed to be of type double, you wil determine which clans battle and wha wil win. Tha clan with the highest value in the given feld will win in a warrior battle aganst he clan with the lowest value in the given feid. Any intermediary clans will not be affected by the battle. Make the folowing updates to the stracture array based on this battle of the field from the given field name (sepond input) which are 1. The winning clan's structure's value in the field given by the secand input should be doubled. 2. The winning clan's structure's value af the Territories fioid, represented by a coil array of strings, should be updated to include the values of the Territories feld in the losing clan's structure. 3. The losing clan's value in the feld given by the second input should be set to zero. 4. The losing clan's value for the Territories fiald should become an empty cell array e values in the teld given by Sort the entire array in descending order based second input Do this using the descend input to sort. In addition to updating the structure array, the function shoud also output a descriptve following format the warrior code, fear leader against losing clan> Example: clans a NaveShadowclan ThunderCIan Brokens Leader: Firestar Territories'southeast woodlands') Strength:8 Territories'northeast sarshes' Strength: 7S [updatedclans, result] arriors(clans, 'Strength') updatedClans NaneThunderclan Leader : Firestar' Territories'southeast woodlands' northeast narshesh Strength168 Nane : ShadowClan Leader : 'Urokenstar' Territories: Strength : Firestar led result Thunderclan to victory against Shadouclan Follouing the warrior code, fearless leader Notes . The input structure array is guaranteed to have the folowing fields: 'Wane eader and Territoriès . It is guaranteed that the values in the field given by the second input wil be a 1x1 double . It is guaranteed that the vaiue in the Territories field wil be a cell array .There will not be any tles.

Explanation / Answer

function [updated,result]=warriors(s,f)
minf=s(1).(f);
maxind=1;
minind=1;
maxf=s(1).(f);
for i=1:length(s)
if s(i).(f)>maxf
maxf=s(i).(f);
maxind=i;
end
if s(i).(f)<minf
minf=s(i).(f);
minind=i;
end
end
result=sprintf('Following the warrior code, fearless leader %s led %s to victory against %s.',s(maxind).Leader,s(maxind).Name,s(minind).Name);
s(maxind).Territories=[s(maxind).Territories s(minind).Territories];
s(minind).Territories={};
s(maxind).(f)=2*s(maxind).(f);
s(minind).(f)=0;
[~,index] = sort([s.(f)],'descend');
for i=1:length(s)
updated(i)=s(index(i));
end