MATLAB: Am I receiving “Error using ones Size inputs must be scalars” when I try to get submatrix with this function

domainkronMATLABMATLAB and Simulink Student Suitematlab functionmatrixsubdomainsubmatrix

Having the next code:
function m=submatrix(k,N)
%% returns submatrix where k is placed
%% N => NxN matrix
n=sqrt(N);
%% create submatrix of nx n elements with different number in order to identify them
aa=[];
aa=kron(1:n,ones(n,n));
b=aa;
for i=1:n-1
b=[b;aa+n*i];
end
vv=b(k);
m=find(b==vv);
end
These are my input parameters:
N = [1 4 3 2;
3 2 4 1;
4 1 2 3;
2 3 1 4];
k = 1;
k = 1 would be 1×1 = 1
k = 5 would be 1×2 = 4
I keep getting an error in line 7: aa=kron(1:n,ones(n,n)), and I'm totally clueless; I tried modifying kron values with similars but I keep getting that.

Best Answer

Then you can't do ones(n,n) since
>> n=sqrt(N)
n =
1.0000 2.0000 1.7321 1.4142
1.7321 1.4142 2.0000 1.0000
2.0000 1.0000 1.4142 1.7321
1.4142 1.7321 1.0000 2.0000