Cody

Problem 1972. Convert matrix to 3D array of triangular matrices

Solution 1451436

Submitted on 27 Feb 2018
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Fail
x = 1:100; y_correct = shiftdim(x,-1); assert(isequal(mat2triu3(x),y_correct))

Error in solution Line: 12 Column: 1 This statement is not inside any function. (It follows the END that terminates the definition of the function "mat2triu3".)

2   Fail
x = reshape(1:15,3,[]); y_correct(:,:,1) = [1 2;0 3]; y_correct(:,:,2) = [4 5;0 6]; y_correct(:,:,3) = [7 8;0 9]; y_correct(:,:,4) = [10 11;0 12]; y_correct(:,:,5) = [13 14;0 15]; assert(isequal(mat2triu3(x),y_correct))

Error in solution Line: 12 Column: 1 This statement is not inside any function. (It follows the END that terminates the definition of the function "mat2triu3".)

3   Fail
x = reshape(1:18,3,[])'; y_correct(:,:,1) = [1 4 10; 0 7 13; 0 0 16]; y_correct(:,:,2) = [2 5 11; 0 8 14; 0 0 17]; y_correct(:,:,3) = [3 6 12; 0 9 15; 0 0 18]; assert(isequal(mat2triu3(x),y_correct))

Error in solution Line: 12 Column: 1 This statement is not inside any function. (It follows the END that terminates the definition of the function "mat2triu3".)

4   Fail
x = randi(50,sum(1:100),22); y = mat2triu3(x); mask = (y~=0); xb = reshape(y(mask),[],size(y,3)); assert(isequal(size(y),[100 100 22])) assert(isequal(x,xb))

Error in solution Line: 12 Column: 1 This statement is not inside any function. (It follows the END that terminates the definition of the function "mat2triu3".)

Suggested Problems

More from this Author44

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!