You are given an M x N matrix. Write a script that will compress this matrix into an M x (N/3) matrix, where each of the terms in the new matrix are the sum of three consecutive terms on each row. You can assume that N is evenly divisible by 3.
For example, if your original matrix is:
[1 7 13 19 25 31 2 8 14 20 26 32 3 9 15 21 27 33 4 10 16 22 28 34 5 11 17 23 29 35 6 12 18 24 30 36]
the output should be
[1+ 7+13 19+25+31 2+ 8+14 20+26+32 3+ 9+15 21+27+33 4+10+16 22+28+34 5+11+17 23+29+35 6+12+18 24+30+36]
or
[21 75 24 78 27 81 30 84 33 87 36 90]
Good luck!
can someone help with this? i dont understand the error message : "Error using SharedVariable1". Thanks
It's not just you. I just tried submitting this solution, and got the same error. Since your line 3 is blank, it probably has something to do with the Cody side of things...
The "line 3" in the error message is actually line 3 in the test suite, rather than the line in your code. I just got a similar error on another Cody problem. "Error using VisibleTest1 (line 4)"
I tested this solution on my own computer, and I got an error which is indeed caused by the floating-points error because the first 3 test cases are checking exact equality by isequal. Thus, simply change your line 5 into "a=filter(ones(1,3),1,x(i,:));" or use an additional round (e.g., a = round(a,10);) should be able to fix the floating-point error as well as this Cody error ("Error using VisibleTest1").
It seems there exist some interference between testing/scoring Cody code, slightly faulty test suite and failing solution. See also solutions 894929 and 894930. This problem has currently 5 tests, but first test begins with "%%a" which comments out first line but it somehow completely disables the display of it and after submission there are only 4 tests shown. On the other hand this solution fails tests 1 and 2 (in original test suite, here is only 2nd shown, under position 1) due to the numeric precision issues (missing tolerance test in tests). What is more interesting the "add problem" page seems to have different version of Cody testing engine and looks more accurate. Anyway, it looks like the error from the first test is copied to the rest. Last three tests should be correct. I expect everything behave correctly after adding newline sign, and tolerance tests in the test suite.
I went in to edit the test suite, and there are no percent signs at the start of the first test suite. When I look in the "Solve This Now!" section, there is. That's strange. I'll add in the new line, rescore, and see how that works.
Looks like it works now.
I had to put in a %% in the first line of the test suite to get everything working. I also added in a tolerance of 1e-10 on all of the test suites, rather than just ones with non-integer values, for those of you who were smart enough to use the filter command. Great detective work, Peng and Jan!
conv never die. nice one!
Return the largest number that is adjacent to a zero
3106 Solvers
3413 Solvers
Calculate the area of a triangle between three points
277 Solvers
Matrix with different incremental runs
193 Solvers
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
229 Solvers