use a function with two inputs, x and y, to create 4 xxy array of 1’s, 8’s, -4.5’s, and 0’s. output the 4 results in order in matlab

You can use the following function in MATLAB to create a 4xxy array of 1's, 8's, -4.5's, and 0's:

main.m
function outputArray = createArray(x, y)
    % Initialize the output array
    outputArray = zeros(4, x, y);

    % Fill the first layer with 1's
    outputArray(1, :, :) = 1;

    % Fill the second layer with 8's
    outputArray(2, :, :) = 8;

    % Fill the third layer with -4.5's
    outputArray(3, :, :) = -4.5;

    % Fill the fourth layer with 0's
    outputArray(4, :, :) = 0;
end
389 chars
17 lines

To use this function, simply call it with your desired values for x and y:

main.m
result = createArray(3, 2);
28 chars
2 lines

The result variable will now contain the 4xxy array with values as you specified.

gistlibby LogSnag