Cody

Problem 2668. Assign matrix elements to separate variables

Solution 2293057

Submitted on 18 May 2020
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
A = rand; B = matsplit(A); assert(isequal(B,A))

A = 0.3926 t = 1×1 cell array {[0.3926]}

Array indices must be positive integers or logical values. Error in matsplit (line 4) matsplit(A)=deal(t{:}) Error in Test1 (line 2) B = matsplit(A);

2   Fail
A = 1:4; [B,C,D,E] = matsplit(A); assert(isequal(B,1)) assert(isequal(C,2)) assert(isequal(D,3)) assert(isequal(E,4))

A = 1 2 3 4 t = 4×1 cell array {[1]} {[2]} {[3]} {[4]}

Error using deal (line 37) The number of outputs should match the number of inputs. Error in matsplit (line 4) matsplit(A)=deal(t{:}) Error in Test2 (line 2) [B,C,D,E] = matsplit(A);

3   Fail
A = magic(3); [B,C,D] = matsplit(A); assert(isequal(B,8)) assert(isequal(C,3)) assert(isequal(D,4))

A = 8 3 4 1 5 9 6 7 2 t = 9×1 cell array {[8]} {[3]} {[4]} {[1]} {[5]} {[9]} {[6]} {[7]} {[2]}

Error using deal (line 37) The number of outputs should match the number of inputs. Error in matsplit (line 4) matsplit(A)=deal(t{:}) Error in Test3 (line 2) [B,C,D] = matsplit(A);

4   Fail
A = eye(4); [B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q] = matsplit(A); assert(isequal(B,1)) assert(isequal(C,0)) assert(isequal(D,0)) assert(isequal(E,0)) assert(isequal(F,0)) assert(isequal(G,1)) assert(isequal(H,0)) assert(isequal(I,0)) assert(isequal(J,0)) assert(isequal(K,0)) assert(isequal(L,1)) assert(isequal(M,0)) assert(isequal(N,0)) assert(isequal(O,0)) assert(isequal(P,0)) assert(isequal(Q,1))

A = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 t = 16×1 cell array {[1]} {[0]} {[0]} {[0]} {[0]} {[1]} {[0]} {[0]} {[0]} {[0]} {[1]} {[0]} {[0]} {[0]} {[0]} {[1]}

Error using deal (line 37) The number of outputs should match the number of inputs. Error in matsplit (line 4) matsplit(A)=deal(t{:}) Error in Test4 (line 2) [B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q] = matsplit(A);

5   Fail
A = fliplr(primes(100))'; B = matsplit(A); assert(isequal(B,97))

A = 97 89 83 79 73 71 67 61 59 53 47 43 41 37 31 29 23 19 17 13 11 7 5 3 2 t = 25×1 cell array {[97]} {[89]} {[83]} {[79]} {[73]} {[71]} {[67]} {[61]} {[59]} {[53]} {[47]} {[43]} {[41]} {[37]} {[31]} {[29]} {[23]} {[19]} {[17]} {[13]} {[11]} {[ 7]} {[ 5]} {[ 3]} {[ 2]}

Error using deal (line 37) The number of outputs should match the number of inputs. Error in matsplit (line 4) matsplit(A)=deal(t{:}) Error in Test5 (line 2) B = matsplit(A);

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!