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

Read the question and follow the direction please. Using matlab Follow these ste

ID: 3681621 • Letter: R

Question

Read the question and follow the direction please. Using matlab

Follow these steps to practice on cell arrays. Each step should have its own lines of code, put inside the same script in that order. Feel free to try them out first on Command Window. Create a cell array called info where you will store your name in the 1st cell, put your major in the 2nd cell, your expected graduation year in the 3rd cell, and the 4th cell will be a vector of your favorite number(s). See example below: Ask the person sitting next to you to provide his/her name, major, graduation year and favorite number(s). Add this information to the second row of the cell array. On a second thought you realized that you would actually graduate one year sooner. Now-change the information in the cell array accordingly. Compare the two majors. If they are same, print the message saying, "My name is Sam Adams and your name is ***. We have the same major." If the majors are different, print the message: "My name is Sam Adams and I'm AE major. Your name is *** and you are *** major." Add a title row to your cell array: name, major, year, and lucky numbers. The title row will be on the first row.

Explanation / Answer

cellarray.m

clc
clear
close all

info{1} = {'Sam Adams' , 'AE' , [2016] , [1 ,2 ,3]};
name = input('Enter your name:');
major = input('Enter your major:');
gradyear = input('Enter your graduation year:');
favnum = zeros;
for i = 1:3
   favnum(i) = input('Enter your favourite number:');
end
a = cell2mat(info{1}(3)) - 1;

info{2} = {name , major , gradyear , favnum};
info{1}(3) = num2cell(a);

nam1 = cell2mat(info{1}(1));
nam2 = cell2mat(info{2}(1));
major1 = cell2mat(info{1}(2));
major2 = cell2mat(info{2}(2));

info{3} = info{2};
info{2} = info{1};
info{1} = {'Name' , 'Major' , 'Year' ,'Lucky Number'};

if (major1 == major2)
   fprintf('My name is %s and your name is %s. We have the same major. ',nam1,nam2)
else
   fprintf('My name is %s and I am %s major. Your name is %s and you are %s major. ',nam1,major1,nam2,major2)
end

%% Result
% Enter your name:'XYZ'
% Enter your major:'NN'
% Enter your graduation year:2014
% Enter your favourite number:1
% Enter your favourite number:2
% Enter your favourite number:4
% My name is Sam Adams and I am AE major. Your name is XYZ and you are NN major.