11.9k views
5 votes
Column arrays: Transpose a row array Construct a row array countValues with elements 1 to endValue, using the double colon operator. Transpose countValues to result in a column array. Function Save Reset MATLAB DocumentationOpens in new tab function countValues = CreateArray(endValue) % endValue: Ending value of countValues % Construct a row array countValues with elements 1 to endValue, % using the double colon operator countValues = 1; % Transpose countValues to result in a column array end 1 2 3 4 5 6 7 8 9 10 11 Code to call your function

1 Answer

3 votes

Answer:

Matlab code with step by step explanation and output results are given below

Step-by-step explanation:

We have to construct a Matlab function that creates a row vector "countValues" with elements 1 to endValue. That means it starts from 1 and ends at the value provided by the user (endValue).

function countValues = CreateArray(endValue)

% Here we construct a row vector countValues from 1:endValue

countValues = 1:endValue;

% then we transpose this row vector into column vector

countValues = countValues';

end

Output:

Calling this function with the endValue=11 returns following output

CreateArray(11)

ans =

1

2

3

4

5

6

7

8

9

10

11

Hence the function works correctly. It creates a row vector then transposes it and makes it a column vector.

Column arrays: Transpose a row array Construct a row array countValues with elements-example-1
User Chris Gutierrez
by
4.1k points