Usually, cells are most useful for storing strings, because the length of each s
ID: 1716120 • Letter: U
Question
Usually, cells are most useful for storing strings, because the length of each string can be unique. Make a 4 Times 4 cell where the first column contains the names: 'William', 'Kelly', 'Bill' and 'Celine', the second column contains their last names: 'Smith', 'Rowland', 'Jackson', 'Dion', the third column contains their occupations: 'Engineer', 'Entertainer', 'Mechanic', 'Singer' and the last column their salaries: $85,000, $650,000, and $50,000, and $1,500,000. Display the cell using disp. 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
clc,
clear all
close all
%A
A=['William' ' ' 'Smith' ' ' 'Engineer' ' ' '$85,000'; 'Kelly' ' ' 'Rowland' ' ' 'Entertainer' ' ' '$65,0000'; 'Bill' ' ' 'Jackson' ' ' 'Mechanic' ' ' '$50,000';'Celine' ' ' 'Dion' ' ' 'Singer' ' ' '$1,500,000'];
disp(A)
%b
x=size(A)
for i=1:x(1)
y=[A(i) A(i+1) A(i+3) A(i+4)]
dis(y)
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.