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

Solution 105956

Submitted on 3 Jul 2012 by James

Correct

91Size
Leading solution size is 20.
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
 
%%
n = 3;
y_correct = nchoosek(1:n,2);
assert(isequal(your_fcn_name(n),y_correct))
% Prevents cheating
filetext = fileread('your_fcn_name.m')
assert(isempty(strfind(filetext, 'nchoosek')))
d =
     1     1     2
filetext =
function output = your_fcn_name(n)
a=1:n;
b=n-a;
c=arrayfun(@(x) repmat(a(x),1,b(x)),1:n,'UniformOutput',false);
d=[c{:}]
e=2:n;
f=arrayfun(@(x) e(x):n,1:n-1,'UniformOutput',false);
g=[f{:}];
output=[d ; g]';
end
%This code written by profile_id 33802
2
Pass
 
%%
n = 25;
y_correct = nchoosek(1:n,2);
assert(isequal(your_fcn_name(n),y_correct))
filetext = fileread('your_fcn_name.m')
assert(isempty(strfind(filetext, 'nchoosek')))
d =
  Columns 1 through 10
     1     1     1     1     1     1     1     1     1     1
  Columns 11 through 20
     1     1     1     1     1     1     1     1     1     1
  Columns 21 through 30
     1     1     1     1     2     2     2     2     2     2
  Columns 31 through 40
     2     2     2     2     2     2     2     2     2     2
  Columns 41 through 50
     2     2     2     2     2     2     2     3     3     3
  Columns 51 through 60
     3     3     3     3     3     3     3     3     3     3
  Columns 61 through 70
     3     3     3     3     3     3     3     3     3     4
  Columns 71 through 80
     4     4     4     4     4     4     4     4     4     4
  Columns 81 through 90
     4     4     4     4     4     4     4     4     4     4
  Columns 91 through 100
     5     5     5     5     5     5     5     5     5     5
  Columns 101 through 110
     5     5     5     5     5     5     5     5     5     5
  Columns 111 through 120
     6     6     6     6     6     6     6     6     6     6
  Columns 121 through 130
     6     6     6     6     6     6     6     6     6     7
  Columns 131 through 140
     7     7     7     7     7     7     7     7     7     7
  Columns 141 through 150
     7     7     7     7     7     7     7     8     8     8
  Columns 151 through 160
     8     8     8     8     8     8     8     8     8     8
  Columns 161 through 170
     8     8     8     8     9     9     9     9     9     9
  Columns 171 through 180
     9     9     9     9     9     9     9     9     9     9
  Columns 181 through 190
    10    10    10    10    10    10    10    10    10    10
  Columns 191 through 200
    10    10    10    10    10    11    11    11    11    11
  Columns 201 through 210
    11    11    11    11    11    11    11    11    11    12
  Columns 211 through 220
    12    12    12    12    12    12    12    12    12    12
  Columns 221 through 230
    12    12    13    13    13    13    13    13    13    13
  Columns 231 through 240
    13    13    13    13    14    14    14    14    14    14
  Columns 241 through 250
    14    14    14    14    14    15    15    15    15    15
  Columns 251 through 260
    15    15    15    15    15    16    16    16    16    16
  Columns 261 through 270
    16    16    16    16    17    17    17    17    17    17
  Columns 271 through 280
    17    17    18    18    18    18    18    18    18    19
  Columns 281 through 290
    19    19    19    19    19    20    20    20    20    20
  Columns 291 through 300
    21    21    21    21    22    22    22    23    23    24
filetext =
function output = your_fcn_name(n)
a=1:n;
b=n-a;
c=arrayfun(@(x) repmat(a(x),1,b(x)),1:n,'UniformOutput',false);
d=[c{:}]
e=2:n;
f=arrayfun(@(x) e(x):n,1:n-1,'UniformOutput',false);
g=[f{:}];
output=[d ; g]';
end
%This code written by profile_id 33802
3
Pass
 
%%
n = 112;
y_correct = nchoosek(1:n,2);
assert(isequal(your_fcn_name(n),y_correct))
filetext = fileread('your_fcn_name.m')
assert(isempty(strfind(filetext, 'nchoosek')))
d =
  Columns 1 through 10
     1     1     1     1     1     1     1     1     1     1
  Columns 11 through 20
     1     1     1     1     1     1     1     1     1     1
  Columns 21 through 30
     1     1     1     1     1     1     1     1     1     1
  Columns 31 through 40
     1     1     1     1     1     1     1     1     1     1
  Columns 41 through 50
     1     1     1     1     1     1     1     1     1     1
  Columns 51 through 60
     1     1     1     1     1     1     1     1     1     1
  Columns 61 through 70
     1     1     1     1     1     1     1     1     1     1
  Columns 71 through 80
     1     1     1     1     1     1     1     1     1     1
  Columns 81 through 90
     1     1     1     1     1     1     1     1     1     1
  Columns 91 through 100
     1     1     1     1     1     1     1     1     1     1
  Columns 101 through 110
     1     1     1     1     1     1     1     1     1     1
  Columns 111 through 120
     1     2     2     2     2     2     2     2     2     2
  Columns 121 through 130
     2     2     2     2     2     2     2     2     2     2
  Columns 131 through 140
     2     2     2     2     2     2     2     2     2     2
  Columns 141 through 150
     2     2     2     2     2     2     2     2     2     2
  Columns 151 through 160
     2     2     2     2     2     2     2     2     2     2
  Columns 161 through 170
     2     2     2     2     2     2     2     2     2     2
  Columns 171 through 180
     2     2     2     2     2     2     2     2     2     2
  Columns 181 through 190
     2     2     2     2     2     2     2     2     2     2
  Columns 191 through 200
     2     2     2     2     2     2     2     2     2     2
  Columns 201 through 210
     2     2     2     2     2     2     2     2     2     2
  Columns 211 through 220
     2     2     2     2     2     2     2     2     2     2
  Columns 221 through 230
     2     3     3     3     3     3     3     3     3     3
  Columns 231 through 240
     3     3     3     3     3     3     3     3     3     3
  Columns 241 through 250
     3     3     3     3     3     3     3     3     3     3
  Columns 251 through 260
     3     3     3     3     3     3     3     3     3     3
  Columns 261 through 270
     3     3     3     3     3     3     3     3     3     3
  Columns 271 through 280
     3     3     3     3     3     3     3     3     3     3
  Columns 281 through 290
     3     3     3     3     3     3     3     3     3     3
  Columns 291 through 300
     3     3     3     3     3     3     3     3     3     3
  Columns 301 through 310
     3     3     3     3     3     3     3     3     3     3
  Columns 311 through 320
     3     3     3     3     3     3     3     3     3     3
  Columns 321 through 330
     3     3     3     3     3     3     3     3     3     3
  Columns 331 through 340
     4     4     4     4     4     4     4     4     4     4
  Columns 341 through 350
     4     4     4     4     4     4     4     4     4     4
  Columns 351 through 360
     4     4     4     4     4     4     4     4     4     4
  Columns 361 through 370
     4     4     4     4     4     4     4     4     4     4
  Columns 371 through 380
     4     4     4     4     4     4     4     4     4     4
  Columns 381 through 390
     4     4     4     4     4     4     4     4     4     4
  Columns 391 through 400
     4     4     4     4     4     4     4     4     4     4
  Columns 401 through 410
     4     4     4     4     4     4     4     4     4     4
  Columns 411 through 420
     4     4     4     4     4     4     4     4     4     4
  Columns 421 through 430
     4     4     4     4     4     4     4     4     4     4
  Columns 431 through 440
     4     4     4     4     4     4     4     4     5     5
  Columns 441 through 450
     5     5     5     5     5     5     5     5     5     5
  Columns 451 through 460
     5     5     5     5     5     5     5     5     5     5
  Columns 461 through 470
     5     5     5     5     5     5     5     5     5     5
  Columns 471 through 480
     5     5     5     5     5     5     5     5     5     5
  Columns 481 through 490
     5     5     5     5     5     5     5     5     5     5
  Columns 491 through 500
     5     5     5     5     5     5     5     5     5     5
  Columns 501 through 510
     5     5     5     5     5     5     5     5     5     5
  Columns 511 through 520
     5     5     5     5     5     5     5     5     5     5
  Columns 521 through 530
     5     5     5     5     5     5     5     5     5     5
  Columns 531 through 540
     5     5     5     5     5     5     5     5     5     5
  Columns 541 through 550
     5     5     5     5     5     6     6     6     6     6
  Columns 551 through 560
     6     6     6     6     6     6     6     6     6     6
  Columns 561 through 570
     6     6     6     6     6     6     6     6     6     6
  Columns 571 through 580
     6     6     6     6     6     6     6     6     6     6
  Columns 581 through 590
     6     6     6     6     6     6     6     6     6     6
  Columns 591 through 600
     6     6     6     6     6     6     6     6     6     6
  Columns 601 through 610
     6     6     6     6     6     6     6     6     6     6
  Columns 611 through 620
     6     6     6     6     6     6     6     6     6     6
  Columns 621 through 630
     6     6     6     6     6     6     6     6     6     6
  Columns 631 through 640
     6     6     6     6     6     6     6     6     6     6
  Columns 641 through 650
     6     6     6     6     6     6     6     6     6     6
  Columns 651 through 660
     6     7     7     7     7     7     7     7     7     7
  Columns 661 through 670
     7     7     7     7     7     7     7     7     7     7
  Columns 671 through 680
     7     7     7     7     7     7     7     7     7     7
  Columns 681 through 690
     7     7     7     7     7     7     7     7     7     7
  Columns 691 through 700
     7     7     7     7     7     7     7     7     7     7
  Columns 701 through 710
     7     7     7     7     7     7     7     7     7     7
  Columns 711 through 720
     7     7     7     7     7     7     7     7     7     7
  Columns 721 through 730
     7     7     7     7     7     7     7     7     7     7
  Columns 731 through 740
     7     7     7     7     7     7     7     7     7     7
  Columns 741 through 750
     7     7     7     7     7     7     7     7     7     7
  Columns 751 through 760
     7     7     7     7     7     7     8     8     8     8
  Columns 761 through 770
     8     8     8     8     8     8     8     8     8     8
  Columns 771 through 780
     8     8     8     8     8     8     8     8     8     8
  Columns 781 through 790
     8     8     8     8     8     8     8     8     8     8
  Columns 791 through 800
     8     8     8     8     8     8     8     8     8     8
  Columns 801 through 810
     8     8     8     8     8     8     8     8     8     8
  Columns 811 through 820
     8     8     8     8     8     8     8     8     8     8
  Columns 821 through 830
     8     8     8     8     8     8     8     8     8     8
  Columns 831 through 840
     8     8     8     8     8     8     8     8     8     8
  Columns 841 through 850
     8     8     8     8     8     8     8     8     8     8
  Columns 851 through 860
     8     8     8     8     8     8     8     8     8     8
  Columns 861 through 870
     9     9     9     9     9     9     9     9     9     9
  Columns 871 through 880
     9     9     9     9     9     9     9     9     9     9
  Columns 881 through 890
     9     9     9     9     9     9     9     9     9     9
  Columns 891 through 900
     9     9     9     9     9     9     9     9     9     9
  Columns 901 through 910
     9     9     9     9     9     9     9     9     9     9
  Columns 911 through 920
     9     9     9     9     9     9     9     9     9     9
  Columns 921 through 930
     9     9     9     9     9     9     9     9     9     9
  Columns 931 through 940
     9     9     9     9     9     9     9     9     9     9
  Columns 941 through 950
     9     9     9     9     9     9     9     9     9     9
  Columns 951 through 960
     9     9     9     9     9     9     9     9     9     9
  Columns 961 through 970
     9     9     9    10    10    10    10    10    10    10
  Columns 971 through 980
    10    10    10    10    10    10    10    10    10    10
  Columns 981 through 990
    10    10    10    10    10    10    10    10    10    10
  Columns 991 through 1000
    10    10    10    10    10    10    10    10    10    10
  Columns 1001 through 1010
    10    10    10    10    10    10    10    10    10    10
  Columns 1011 through 1020
    10    10    10    10    10    10    10    10    10    10
  Columns 1021 through 1030
    10    10    10    10    10    10    10    10    10    10
  Columns 1031 through 1040
    10    10    10    10    10    10    10    10    10    10
  Columns 1041 through 1050
    10    10    10    10    10    10    10    10    10    10
  Columns 1051 through 1060
    10    10    10    10    10    10    10    10    10    10
  Columns 1061 through 1070
    10    10    10    10    10    11    11    11    11    11
  Columns 1071 through 1080
    11    11    11    11    11    11    11    11    11    11
  Columns 1081 through 1090
    11    11    11    11    11    11    11    11    11    11
  Columns 1091 through 1100
    11    11    11    11    11    11    11    11    11    11
  Columns 1101 through 1110
    11    11    11    11    11    11    11    11    11    11
  Columns 1111 through 1120
    11    11    11    11    11    11    11    11    11    11
  Columns 1121 through 1130
    11    11    11    11    11    11    11    11    11    11
  Columns 1131 through 1140
    11    11    11    11    11    11    11    11    11    11
  Columns 1141 through 1150
    11    11    11    11    11    11    ...
4
Pass
 
%%
n = 2
y_correct = nchoosek(1:n,2);
assert(isequal(your_fcn_name(n),y_correct))
filetext = fileread('your_fcn_name.m')
assert(isempty(strfind(filetext, 'nchoosek')))
n =
     2
d =
     1
filetext =
function output = your_fcn_name(n)
a=1:n;
b=n-a;
c=arrayfun(@(x) repmat(a(x),1,b(x)),1:n,'UniformOutput',false);
d=[c{:}]
e=2:n;
f=arrayfun(@(x) e(x):n,1:n-1,'UniformOutput',false);
g=[f{:}];
output=[d ; g]';
end
%This code written by profile_id 33802