use matlab Homework 10- Structures Function Name: garfield Inputs 1. (struct) A
ID: 3736294 • Letter: U
Question
use matlab
Homework 10- Structures Function Name: garfield Inputs 1. (struct) A 1xN structure array containing information about cats Outputs 1. (struct) A 1xM updated structure array with no occurrences of Monday Background with a lady cat friend. The only problem is that you know how much he hates Mondays, and that Garfield is a grumpy cat. You think that you could make him happier by setting him up any mention of the word will set him off and your plan will fail. Luckily, you have MATLAB to ensure that all of the lovely candidates are safe to meet Garfield. Function Description: Write a function that iterates through the fields of a structure vector. If any of the fields a structure in the array contain the value 'Monday, regardless of case, then entire structure should be removed. Example >> struct Name:'Monday Color: 'Black' Name: 'Lucy Name: 'PrincessName: 'Crookshanks Color: 'Gray Color: 'white Color: 'Orange' faveword: 'Lasagna faveword: 'No' faveword: mondayfavekord: 'Magic >> newstruct - garfield(struct) newStruct Name: Lucy Color: Gray faveWord: No Name: 'Crookshanks Color: 'Orange faveword: 'Magic Notes: The function should be case insensitive it should delete a structure containing monday regardless of capitalization. The word monday' will NOT be a substring of another valueExplanation / Answer
function newS=garfield(S) fields=(fieldnames(S)); l=length(S); k=1; for i=1:l n=0; for j=1:numel(fields) if strcmpi(S(i).(fields{j}),'monday') n=n+1; end end if n==0 newS(k)=S(i); k=k+1; end end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.