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

Problem-2: Cells Usually, cells are most useful for storing strings, because the

ID: 1993573 • Letter: P

Question

Problem-2: Cells Usually, cells are most useful for storing strings, because the length of each string can be unique. a. Make a 4x4 cell where the first column contains the names: ‘Kevin’, ‘Natasha’, ‘Dak’ and ‘Usain’, the second column contains their last names: ‘Hart’, ‘St. Pier’, ‘Prescott’, ‘Bolt’, the third column contains their occupations: ‘Comedian’, ‘Singer’, ‘Quaterback’, ‘Athlete’ and the last column their salaries: $850,000, $650,000, and $1,500,000, and $2,00,000. Display the cell using disp. b. Modify the code you obtained in a. such that it displays a sentence of the form “[First Name], [Last Name] is a/an [Occupation] and has a salary of [Salary]”. Do this using a “for loop” and display the sentences.

Explanation / Answer

clear
d=cell(4);
d(1,1)=cellstr('Kevin')
d(1,2)=cellstr('Natasha')
d(1,3)=cellstr('Dak')
d(1,4)=cellstr('Usain')
d(2,1)=cellstr('Hart')
d(2,2)=cellstr('St. Pier')
d(2,3)=cellstr('Prescott')
d(2,4)=cellstr('Bolt')
d(3,1)=cellstr('Comedian')
d(3,2)=cellstr('Singer')
d(3,3)=cellstr('Quaterback')
d(3,4)=cellstr('Athlete')
d(4,1)=cellstr('$850,000')
d(4,2)=cellstr('$650,000')
d(4,3)=cellstr('$1,500,000')
d(4,4)=cellstr('$2,00,000')
S = cell2struct(d,{'f1','f2','f3','f4'},2);
fields = fieldnames(S)
for i=1:numel(fields)
[FN,LN,Occ,Sa]=S.(fields{i});
fprintf('%s %s is a/an %s and has a salary of %s ',FN,LN,Occ,Sa);
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote