Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
filetext = fileread('your_fcn_name.m')
assert(~isempty(strfind(filetext, 'gallery')))
assert( isempty(strfind(filetext, '% gallery')))
filetext =
'function f = your_fcn_name(n)
% code
count = 0;
for III = 1:n
if rem(III,2) == 1
count = count+1;
end
end
a = n-count;
b = zeros(n-a,n-a);
for I = 1:n-a
b(I,I) = 1;
end
c = I-1;
for II = I+1:n
b(c,II) = 1;
c = c-1;
end
d = b;
d(1,:) =[];
e = flipud(d);
f = [e;b];
f = logical(f)
end
%This code written by profile_id 9486485
'
|
2 | Pass |
n = 5;
expected = [0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0];
y_correct = logical(expected)
assert(isequal(your_fcn_name(n),y_correct))
y_correct =
5×5 logical array
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0
f =
5×5 logical array
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0
|
3 | Pass |
n = 9;
expected = [ 0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
0 0 1 0 0 0 1 0 0
0 1 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0]
y_correct = logical(expected)
assert(isequal(your_fcn_name(n),y_correct))
expected =
0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
0 0 1 0 0 0 1 0 0
0 1 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0
y_correct =
9×9 logical array
0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
0 0 1 0 0 0 1 0 0
0 1 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0
f =
9×9 logical array
0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
0 0 1 0 0 0 1 0 0
0 1 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0
|
1961 Solvers
556 Solvers
168 Solvers
Back to basics 22 - Rotate a matrix
763 Solvers
349 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!