20.8k views
4 votes
Concatenating arrays Assign studentIDs with concatenated row arrays groupA and groupB. Function Save Reset MATLAB DocumentationOpens in new tab function studentIDs = CombineIDs(groupA, groupB) % groupA: row array of group A's student IDs % groupB: row array of group B's student IDs % Assign studentIDs with concatenated row arrays groupA and groupB studentIDs = 0; end 1 2 3 4 5 6 7 8 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 simple Matlab function named "studentIDs" that accepts two arguments row arrays groupA and groupB and returns the concatenated row array containing the elements of groupA and groupB.

function studentIDs = CombineIDs(groupA, groupB)

% here we concatenated the two row arrays together.

studentIDs=[groupA groupB];

% If you want to make it a column array then place a semicolon between groupA and groupB

end

Output:

Calling this function with groupA=[100, 101] and groupB=[230, 231, 232] returns the following output:

CombineIDs([100,101], [230, 231, 232])

ans = 100 101 230 231 232

Calling this function with groupA=[1, 2, 3] and groupB=[4, 5, 6, 7, 8] returns the following output:

CombineIDs([1,2,3], [4,5,6,7,8])

ans = 1 2 3 4 5 6 7 8

Hence the function correctly concatenates the two row arrays together.

User Adam Sibik
by
8.5k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories