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
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.)
I will post the code I have below, my issue is with the vector of class double, how do I declare a vector of class double and have it output correctly? Currently it outputs the first two parts of the cell array just fine, it also outputs the first number in the vector fine, but the second numbers are output as weird symbols.
Here is the printer function:
function [x, y, z] = printer(celly) %supposed to print stuff %access values from celly below x = celly{1}; y = celly{2}; z = celly{3}; if size(z) > 4 fprintf("Bad input ") return; end fprintf("%s %d %g ",x,y,z); end
Here is the main code:
a = 'hey there'; b = uint8(12); c = [12 3 5]; celly = {a,b,c}; printer(celly);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
