Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Correct

56Size
Leading solution size is 41.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
m=magic(20);
MagicConstant=pandiag(m);
assert(isequal(MagicConstant,0))

                    
2
Pass
 
%%
m=[41 137 149 19 37 6427 6343 6277 6449 6353 131 211 397 281 431 6421 6329 6197 6271 6199
557 29 367 59 173 5923 6121 6101 6163 6287 643 827 929 947 769 5897 6043 5623 5851 5791
419 571 631 853 919 6053 5801 5783 5573 5387 859 1229 857 1201 1487 5689 5419 5749 5393 5227
1061 1103 1231 661 1093 5323 5381 5231 5189 5273 1847 2293 1499 2281 1867 4789 4243 5059 4889 4787
1249 1277 1423 1889 1997 5051 4951 4931 4241 4373 2239 2309 2069 2731 2377 4481 4483 4597 4159 4273
241 337 607 683 773 6311 6203 5987 5869 5857 151 263 359 421 379 6317 6217 6067 6047 6011
1039 1301 1553 1697 1759 5501 5569 4999 5101 4801 953 503 991 809 1163 5527 5647 5477 5413 5297
1471 2087 2003 1871 2357 5077 4561 4603 4723 4357 1031 1429 1777 1523 1789 5441 4943 4637 4903 4517
2647 3823 2381 3709 3593 3989 2713 4177 3461 3061 1861 2633 2113 2089 2819 4523 3851 4349 3761 3547
3373 3253 3323 3583 3259 3347 3539 3343 3307 3391 2383 2221 2677 2741 2879 3917 4007 3677 3389 3491
6379 6299 6113 6229 6079 89 181 313 239 311 6469 6373 6361 6491 6473 83 167 233 61 157
5867 5683 5581 5563 5741 613 467 887 659 719 5953 6481 6143 6451 6337 587 389 409 347 223
5651 5281 5653 5309 5023 821 1091 761 1117 1283 6091 5939 5879 5657 5591 457 709 727 937 1123
4663 4217 5011 4229 4643 1721 2267 1451 1621 1723 5449 5407 5279 5849 5417 1187 1129 1279 1321 1237
4271 4201 4441 3779 4133 2029 2027 1913 2351 2237 5261 5233 5087 4621 4513 1459 1559 1579 2269 2137
6359 6247 6151 6089 6131 193 293 443 463 499 6269 6173 5903 5827 5737 199 307 523 641 653
5557 6007 5519 5701 5347 983 863 1033 1097 1213 5471 5209 4957 4813 4751 1009 941 1511 1409 1709
5479 5081 4733 4987 4721 1069 1567 1873 1607 1993 5039 4423 4507 4639 4153 1433 1949 1907 1787 2153
4649 3877 4397 4421 3691 1987 2659 2161 2749 2963 3863 2687 4129 2801 2917 2521 3797 2333 3049 3449
4127 4289 3833 3769 3631 2593 2503 2833 3121 3019 3137 3257 3187 2927 3251 3163 2971 3167 3203 3119];
MagicConstant=pandiag(m);
assert(isequal(MagicConstant,65100))

                    
3
Pass
 
%%
m=[5 73 127 137 53
37 167 17 71 103
83 101 13 67 131
43 31 197 113 11
227 23 41 7 97];
MagicConstant=pandiag(m);
assert(isequal(MagicConstant,395))

                    
4
Pass
 
%%
m=[191	89	397	409	43	157	311
379	103	101	491	17	313	193
317	241	109	163	439	47	281
223	383	227	107	541	37	79
331	337	7	139	167	563	53
83	347	389	277	127	307	67
73	97	367	11	263	173	613];
MagicConstant=pandiag(m);
assert(isequal(MagicConstant,1597))

                    
5
Pass
 
%%
m=[191	89	397	409	43	157	311
379	103	101	491	17	313	193
317	241	109	163	439	47	281
223	383	227	107	541	37	79
331	337	7	139	167	3	53
83	347	389	277	127	307	67
73	97	367	11	263	173	613];
MagicConstant=pandiag(m);
assert(isequal(MagicConstant,0))

                    
6
Pass
 
%%
m=magic(7);
MagicConstant=pandiag(m);
assert(isequal(MagicConstant,0))