Cody

Problem 42783. Accessing values in a cell

Solution 2142850

Submitted on 27 Feb 2020 by Asif Newaz
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
format compact c=cell(1,3); c{1}=2:6;c{2}=7:12;c{3}=13:18; a=[1 2 3];b=[4 5 6]; y_correct = [5 11 18]; assert(isequal(break_cells_down(c,a,b),y_correct))

x = 2 3 4 5 6 y = 5 x = 7 8 9 10 11 12 y = 5 11 x = 13 14 15 16 17 18 y = 5 11 18

2   Pass
clear c c=cell(1,5); c{1}=rand(1,10); c{2}=rand(1,10); c{3}=rand(1,10); c{4}=rand(1,10); c{5}=rand(1,10); a=randperm(5) b=randperm(10); b=b(1:5) y_correct=[c{a(1)}(b(1)) c{a(2)}(b(2)) c{a(3)}(b(3)) c{a(4)}(b(4)) c{a(5)}(b(5))] assert(isequal(break_cells_down(c,a,b),y_correct))

a = 1 2 4 3 5 b = 4 5 3 6 10 y_correct = 0.2701 0.4315 0.3326 0.8600 0.5539 x = 0.9375 0.1566 0.2669 0.2701 0.2656 0.3715 0.2402 0.2482 0.7100 0.4311 y = 0.2701 x = 0.0215 0.2042 0.1078 0.0888 0.4315 0.6646 0.8164 0.6537 0.3332 0.0121 y = 0.2701 0.4315 x = 0.9186 0.3330 0.3326 0.2645 0.5664 0.9069 0.0281 0.1838 0.2665 0.4573 y = 0.2701 0.4315 0.3326 x = 0.4551 0.8173 0.4356 0.9297 0.1378 0.8600 0.7528 0.8592 0.1162 0.9773 y = 0.2701 0.4315 0.3326 0.8600 x = 0.4909 0.6714 0.4709 0.1438 0.9036 0.0511 0.3591 0.3059 0.5588 0.5539 y = 0.2701 0.4315 0.3326 0.8600 0.5539

3   Pass
clear c c=cell(1,6); c{1}=1:6; c{2}=1:6; c{3}=1:6; c{4}=1:6; c{5}=1:6; c{6}=1:6; a=1:6; b=randperm(6) y_correct=b; assert(isequal(break_cells_down(c,a,b),y_correct))

b = 5 2 4 1 3 6 x = 1 2 3 4 5 6 y = 5 x = 1 2 3 4 5 6 y = 5 2 x = 1 2 3 4 5 6 y = 5 2 4 x = 1 2 3 4 5 6 y = 5 2 4 1 x = 1 2 3 4 5 6 y = 5 2 4 1 3 x = 1 2 3 4 5 6 y = 5 2 4 1 3 6