Problem2 Cells Usually cells are most useful for storing str

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.

Solution

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

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site