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

Incorrect

29Size
Leading solution size is 29.
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
 
% no diag
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, 'diag')))

                    
2
Fail
 
%%  square m-by-m matrix (1)
x = [10 20 30; 40 50 60; 70 80 90];
diag_correct =  [10 50 90];
antidiag_correct = [ 70    50    30];
[A,B]= your_fcn_name(x);
assert(isequal(A,diag_correct))
assert(isequal(B,antidiag_correct))
Error: Subscript indices must either be real positive integers or logicals.
3
Fail
 
%% m-by-n matrix where m >= n (2)
x = [10 20 30; 40 50 60  ; 70 80 90; 100 74 15];
diag_corrct78 =  [10 50 90];
antidiag_corrct78 = [ 100   80    60];
[A3,B3]= your_fcn_name(x);
assert(isequal(A3,diag_corrct78))
assert(isequal(B3,antidiag_corrct78))
Error: Subscript indices must either be real positive integers or logicals.
4
Fail
 
%% m-by-n matrix where m <= n (3)
x = [10 20 30 58; 40 50 60 68 ; 70 80 90 98];
diag_correct7 =  [10 50 90];
antidiag_correct7 = [ 70    50    30];
[A3,B3]= your_fcn_name(x);
assert(isequal(A3,diag_correct7))
assert(isequal(B3,antidiag_correct7))
Error: Subscript indices must either be real positive integers or logicals.
5
Fail
 
%% m-by-n matrix where m >= n (4)
t = [0 0 0; 1 0 0 ; 0  2 0; 0 0 3];
diag8 =  [0 0 0];
antid7 = [ 0 2 0];
[A3,B3]= your_fcn_name(t);
assert(isequal(A3,diag8))
assert(isequal(B3,antid7))
% m-by-n matrix where m <= n (5)
t = [0 1 0 0; 0 0 2 0 ; 0 0 0 3];
diag8 =  [0 0 0];
antid7 = [ 0 0 0];
[A3,B3]= your_fcn_name(t);
assert(isequal(A3,diag8))
assert(isequal(B3,antid7))
Error: Subscript indices must either be real positive integers or logicals.