Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Correct

29Size
This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
format long
format compact
seed=clock;
seed=1000*seed(6);
rng(seed)
n=4;
% Create a Unique element square array
M=randperm(n*n);
M=reshape(M,n,n)
vr=M(1:n,:);
vr=sortrows(vr);
vc=M(:,1:n);
vc=sortrows(vc')';
tic
M_out=Criss_Cross(vr,vc);
toc
M_out
assert(isequal(M,M_out));
M =
    13    12     9    11
     2     1    16     7
    10     3     5     6
    14    15     4     8
Elapsed time is 0.060577 seconds.
M_out =
    13    12     9    11
     2     1    16     7
    10     3     5     6
    14    15     4     8
2
Pass
 
%%
seed=clock;
seed=1000*seed(6);
rng(seed)
n=8;
% Create a Unique element square array
M=randperm(n*n);
M=reshape(M,n,n)
vr=M(1:n,:);
vr=sortrows(vr);
vc=M(:,1:n);
vc=sortrows(vc')';
tic
M_out=Criss_Cross(vr,vc);
toc
M_out
assert(isequal(M,M_out));
M =
    17     1    10    38     9    56    46     5
    43     4    32    34    24    50    55    40
    16    18     7    15    49    39    21    26
    35    22     3    13    61    57    47    30
    28    59    42    48    31    45    53    51
    20    33    44    11    27    54    63    64
    62     2     6    36     8    19    52    23
    14    41    37    58    29    12    25    60
Elapsed time is 0.001068 seconds.
M_out =
    17     1    10    38     9    56    46     5
    43     4    32    34    24    50    55    40
    16    18     7    15    49    39    21    26
    35    22     3    13    61    57    47    30
    28    59    42    48    31    45    53    51
    20    33    44    11    27    54    63    64
    62     2     6    36     8    19    52    23
    14    41    37    58    29    12    25    60
3
Pass
 
%%
seed=clock;
seed=1000*seed(6);
rng(seed)
n=128;
% Create a Unique element square array
M=randperm(n*n);
M=reshape(M,n,n);
vr=M(1:n,:);
vr=sortrows(vr);
vc=M(:,1:n);
vc=sortrows(vc')';
tic
M_out=Criss_Cross(vr,vc);
toc
assert(isequal(M,M_out));
Elapsed time is 0.010583 seconds.
4
Pass
 
%%
seed=clock;
seed=1000*seed(6);
rng(seed)
n=1024;
% Create a Unique element square array
M=randperm(n*n);
M=reshape(M,n,n);
vr=M(1:n,:);
vr=sortrows(vr);
vc=M(:,1:n);
vc=sortrows(vc')';
tic
M_out=Criss_Cross(vr,vc);
toc
assert(isequal(M,M_out));
Elapsed time is 0.913746 seconds.
5
Pass
 
%%
seed=clock;
seed=1000*seed(6);
rng(seed)
n=4096;
% Create a Unique element square array
M=randperm(n*n);
M=reshape(M,n,n);
vr=M(1:n,:);
vr=sortrows(vr);
vc=M(:,1:n);
vc=sortrows(vc')';
tic
M_out=Criss_Cross(vr,vc);
toc
assert(isequal(M,M_out));
Elapsed time is 37.384201 seconds.