Cody

# Problem 42590. Divide elements by sum of elements

Solution 1905530

Submitted on 20 Aug 2019
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
filetext = fileread('divideElements.m'); assert(isempty(strfind(filetext, 'for'))) assert(isempty(strfind(filetext, 'while')))

2   Pass
x = magic(3); y_correct = [0.53 0.07 0.4; 0.20 0.33 0.47; 0.27 0.60 0.13]; assert(isequal(divideElements(x),y_correct))

y = 0.5300 0.0700 0.4000 0.2000 0.3300 0.4700 0.2700 0.6000 0.1300

3   Fail
x = magic(4); y_correct = [0.47 0.06 0.09 0.38 0.15 0.32 0.29 0.24 0.26 0.21 0.18 0.35 0.12 0.41 0.44 0.03]; assert(isequal(divideElements(x),y_correct))

Matrix dimensions must agree. Error in divideElements (line 2) y=round(x./repmat(sum(x,1),3,1),2) Error in Test3 (line 6) assert(isequal(divideElements(x),y_correct))

4   Fail
x = ones(2); y_correct = repmat(0.5,2,2); assert(isequal(divideElements(x),y_correct))

Matrix dimensions must agree. Error in divideElements (line 2) y=round(x./repmat(sum(x,1),3,1),2) Error in Test4 (line 3) assert(isequal(divideElements(x),y_correct))

5   Fail
x = [1 0.5; 2 1]; y_correct = [0.33 0.33; 0.67 0.67]; assert(isequal(divideElements(x),y_correct))

Matrix dimensions must agree. Error in divideElements (line 2) y=round(x./repmat(sum(x,1),3,1),2) Error in Test5 (line 3) assert(isequal(divideElements(x),y_correct))