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

MATLAB Prepare a function m-file containing a function that prints a line (to th

ID: 3596111 • Letter: M

Question

MATLAB

Prepare a function m-file containing a function that prints a line (to the command window), where the line consists of a string, the value of a (scalar) unsigned integer, and the values of the elements in a vector. All these components should print on one line with white space between the different components.

The input will be a cell array. The first cell will contain the string. The second cell will contain the (scalar) unsigned integer having class uint8. The third cell will contain the vector of class double. This function should work if the vector is of length 1, 2, 3, or 4. There will be no output variables.

In the second section of your script m-file, generate 2 different cell arrays to test your function. You can use any values you want. However, the length of the vector should be different for the 2 different cell arrays. (This will demonstrate that your function works for more than just one particular vector length.)

So this is the code I have, my issue is understanding how to take a function and pass a cell array to it with the required types.

This is my main:

a = 'hey there';
b = uint8(12);
c = (0:20:3);
celly = {a,b,c};
printer(celly);

This is my function:

function [x, y, z] = printer{string, int, vector};
    %supposed to print stuff
    x = string;
    y = int;
    z = vector;
    if size(vector) > 4
        fprintf("Bad input ")
        return;
    end
    fprintf(string)
    fprintf(int)


    fprintf(vector)
end

Explanation / Answer

function [x, y, z] = printer(celly)
%supposed to print stuff
%access the values from celly
x = celly{1};
y = celly{2};
z = celly{3};
if size(z) > 4
fprintf("Bad input ")
return;
end
%fprintf format %s for string %d for integer %g for array
fprintf("%s %d %g",x,y,z)
end
a = 'hey there';
b = uint8(12);
c = (0:20:3);
celly = {a,b,c}
printer(celly);