MATLAB: Is there a simpler or more efficient way to do the following

helphomeworkMATLABprojectquestion

The assignment was to: "Write a program (function) that takes in an non-empty integer array A with unknown rows and columns and return an string matrix B with matrix A is padded at left hand side with row number followed by a tab character (char(9))and on top with column number"
The code I came up with and that seems to work is the following:
function B = label(A)
%Function to label rows and columns in an array with numbers
B = string(A);
% sets B to the string version of the A array
[~,columnsInB] = size(B);
% gets the current size of our array
insertRow = zeros(1,columnsInB);
% creates a placeholder to use later in inserting a row
rowToInsert = 1;
% defines which row we will insert on
columnToInsert = 1;
% defines which column we will insert on
B = [B(1:rowToInsert-1,:); insertRow; B(rowToInsert:end,:)];
% set the string array B to a copy of it which has the extra inserted

% row
[rowsInB,~] = size(B);
% gets new size of array

insertColumn = zeros(rowsInB,1);
% creates a placeholder to use later in inserting a column
B = [B(:,1:columnToInsert-1), insertColumn, B(:,columnToInsert:end)];
% set the string array B to a copy of it which has the extra inserted
% column
[rowsInB,columnsInB] = size(B);
% gets new size of array
B(1) = ' ';
% sets the first value to nothing
for rows = 2:rowsInB
% loop to add row numbers to the first column with the indent
B(rows) = (rows - 1+" ");
end
for columns = 2:columnsInB
% loop to add column numbers to the first row
B(1, columns) = columns - 1;
end
end

Best Answer

You could for example do this
function B = label1(A)
[rows,cols] = size(A);
B = ["",string(1:cols);[string((1:rows)')+char(9),A]];
end
I don't claim that it is simpler/more efficient, nor the most compact. Mixed feelings on whether it is a useful learning/teaching snippet either.
Likely the hw problem was written before "strings" were actually a thing, and the answer saught is a character array. At least that would be the more interesting hw problem to pose imho.