Cody

Problem 2585. How to reverse spdiags ?

Solution 1940581

Submitted on 17 Sep 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   Fail
x = spdiags([1 2 3;4 5 6;7 8 9]); assert(isequal(spdiags(inv_spdiags(x)),x))

m = 0 0 0 0 0 0 0 0 0

Unable to perform assignment because the left and right sides have a different number of elements. Error in inv_spdiags (line 9) m(sub2ind([r,c],caselle(1,:),caselle(2,:))) = x(1:i,i); Error in Test1 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

2   Fail
b = spdiags(eye(10)); assert(isequal(spdiags(inv_spdiags(b)),b))

m = 0×10 empty double matrix

Index in position 2 exceeds array bounds (must not exceed 1). Error in inv_spdiags (line 9) m(sub2ind([r,c],caselle(1,:),caselle(2,:))) = x(1:i,i); Error in Test2 (line 2) assert(isequal(spdiags(inv_spdiags(b)),b))

3   Fail
x = spdiags([1 2 3;4 5 6]); assert(isequal(spdiags(inv_spdiags(x)),x))

m = 0 0 0 0 0 0

Unable to perform assignment because the left and right sides have a different number of elements. Error in inv_spdiags (line 9) m(sub2ind([r,c],caselle(1,:),caselle(2,:))) = x(1:i,i); Error in Test3 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

4   Fail
y = spdiags(magic(9)); assert(isequal(spdiags(inv_spdiags(y)),y))

m = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Unable to perform assignment because the left and right sides have a different number of elements. Error in inv_spdiags (line 9) m(sub2ind([r,c],caselle(1,:),caselle(2,:))) = x(1:i,i); Error in Test4 (line 2) assert(isequal(spdiags(inv_spdiags(y)),y))

5   Fail
x = spdiags(magic(5)); assert(isequal(spdiags(inv_spdiags(x)),x))

m = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Unable to perform assignment because the left and right sides have a different number of elements. Error in inv_spdiags (line 9) m(sub2ind([r,c],caselle(1,:),caselle(2,:))) = x(1:i,i); Error in Test5 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

6   Fail
z = spdiags(ones(10)); assert(isequal(spdiags(inv_spdiags(z)),z))

m = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Unable to perform assignment because the left and right sides have a different number of elements. Error in inv_spdiags (line 9) m(sub2ind([r,c],caselle(1,:),caselle(2,:))) = x(1:i,i); Error in Test6 (line 2) assert(isequal(spdiags(inv_spdiags(z)),z))

7   Fail
x = spdiags(randi(10,5)); assert(isequal(spdiags(inv_spdiags(x)),x))

m = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Unable to perform assignment because the left and right sides have a different number of elements. Error in inv_spdiags (line 9) m(sub2ind([r,c],caselle(1,:),caselle(2,:))) = x(1:i,i); Error in Test7 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

8   Fail
x = spdiags(randi(5,[3 2])); assert(isequal(spdiags(inv_spdiags(x)),x))

m = 0 0 0 0 0 0

Unable to perform assignment because the left and right sides have a different number of elements. Error in inv_spdiags (line 9) m(sub2ind([r,c],caselle(1,:),caselle(2,:))) = x(1:i,i); Error in Test8 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

9   Fail
a = spdiags(zeros(5)); assert(isequal(spdiags(inv_spdiags(a)),a))

m = 0×5 empty double matrix

Index in position 2 exceeds array bounds. Error in inv_spdiags (line 9) m(sub2ind([r,c],caselle(1,:),caselle(2,:))) = x(1:i,i); Error in Test9 (line 2) assert(isequal(spdiags(inv_spdiags(a)),a))

Community Treasure Hunt

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

Start Hunting!