Cody

# Problem 2668. Assign matrix elements to separate variables

Solution 803649

Submitted on 9 Jan 2016 by Michael Cappello
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   Pass
%% A = rand; B = matsplit(A); assert(isequal(B,A))

varargout = [0.7542]

2   Pass
%% 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))

varargout = [1] varargout = [1] [2] varargout = [1] [2] [3] varargout = [1] [2] [3] [4]

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

varargout = [8] varargout = [8] [3] varargout = [8] [3] [4]

4   Pass
%% 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))

varargout = [1] varargout = [1] [0] varargout = [1] [0] [0] varargout = [1] [0] [0] [0] varargout = [1] [0] [0] [0] [0] varargout = [1] [0] [0] [0] [0] [1] varargout = [1] [0] [0] [0] [0] [1] [0] varargout = [1] [0] [0] [0] [0] [1] [0] [0] varargout = [1] [0] [0] [0] [0] [1] [0] [0] [0] varargout = [1] [0] [0] [0] [0] [1] [0] [0] [0] [0] varargout = [1] [0] [0] [0] [0] [1] [0] [0] [0] [0] [1] varargout = [1] [0] [0] [0] [0] [1] [0] [0] [0] [0] [1] [0] varargout = [1] [0] [0] [0] [0] [1] [0] [0] [0] [0] [1] [0] [0] varargout = [1] [0] [0] [0] [0] [1] [0] [0] [0] [0] [1] [0] [0] [0] varargout = Columns 1 through 14 [1] [0] [0] [0] [0] [1] [0] [0] [0] [0] [1] [0] [0] [0] Column 15 [0] varargout = Columns 1 through 14 [1] [0] [0] [0] [0] [1] [0] [0] [0] [0] [1] [0] [0] [0] Columns 15 through 16 [0] [1]

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

varargout = [97]

### Community Treasure Hunt

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

Start Hunting!