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

Please help write function in Matlab Write a function with the header: function

ID: 3665535 • Letter: P

Question

Please help write function in Matlab

Write a function with the header: function [out] = myMakeName5(nameStr) which returns the first 5 characters of nameStr. If nameStr is less than 5 characters, it pre-pads the name with underscores (_). The function should also check to make sure the input has data type char (use isa or ischar) and if it is not, writes a message to the user and returns the word “err”.

Test Cases:

>> myMakeName5('Sebastian')

ans = Sebas

>> myMakeName5('Bob')

ans = __Bob

>> myMakeName5('Marco')

ans = Marco

Explanation / Answer

When you run the file, it produces the following result

USPres_s1(1).name = 'Franklin D. Roosevelt';
USPres_s1(1).party = 'Democratic';
USPres_s1(1).term = {1933, 1945};
USPres_s1(1).vp = ...
{'John Garner';'Henry Wallace';'Harry S Truman'};
USPres_s1(2).name = 'Harry S Truman';
USPres_s1(2).party = 'Democratic';
USPres_s1(2).term = {1945, 1953};
USPres_s1(2).vp = 'Alben Barkley';
whos USPres_s1
Name Size Bytes Class Attributes
USPres_s1 1x2 1400 struct
Convert the struct array to a cell array:
USPres_c1 = struct2cell(USPres_s1);
whos USPres_c1
Name Size Bytes Class Attributes
USPres_c1 4x1x2 1144 cell
Convert back to a struct array and compare it with the original:
USPres_s2 = cell2struct(USPres_c1, ...
{'name','party','term','vp'}, 1);
whos USPres_s2
Name Size Bytes Class Attributes
USPres_s2 1x2 1400 struct
isequal(USPres_s1, USPres_s2)
ans =
1-91
1 Classes (Data Types)
1
Organizing Data in Stru