Cody

Problem 1699. Find last zero for each column

Solution 2481356

Submitted on 6 Jun 2020 by ChrisR
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
a = 0; z_correct = 1; assert(isequal(lastzerorow(a),z_correct))

indx = 1

2   Pass
a = 1; z_correct = 0; assert(isequal(lastzerorow(a),z_correct))

indx = []

3   Pass
a = randi(1000,1000,1); z_correct = 0; assert(isequal(lastzerorow(a),z_correct))

indx = 0×1 empty double column vector

4   Pass
a = [0;1;0;2;0;3;0;4;0;5;0;6;0;7;0;8;0;9;0;10]; z_correct = 19; assert(isequal(lastzerorow(a),z_correct))

indx = 19

5   Pass
n = randi(1000); a = tril(ones(n)); z_correct = 0:n-1; assert(isequal(lastzerorow(a),z_correct))

indx = 0×1 empty double column vector indx = 1 indx = 2 indx = 3 indx = 4 indx = 5 indx = 6 indx = 7 indx = 8 indx = 9 indx = 10 indx = 11 indx = 12 indx = 13 indx = 14 indx = 15 indx = 16 indx = 17 indx = 18 indx = 19 indx = 20 indx = 21 indx = 22 indx = 23 indx = 24 indx = 25 indx = 26 indx = 27 indx = 28 indx = 29 indx = 30 indx = 31 indx = 32 indx = 33 indx = 34 indx = 35 indx = 36 indx = 37 indx = 38 indx = 39 indx = 40 indx = 41 indx = 42 indx = 43 indx = 44 indx = 45 indx = 46 indx = 47 indx = 48 indx = 49 indx = 50 indx = 51 indx = 52 indx = 53 indx = 54 indx = 55 indx = 56 indx = 57 indx = 58 indx = 59 indx = 60 indx = 61 indx = 62 indx = 63 indx = 64 indx = 65 indx = 66 indx = 67 indx = 68 indx = 69 indx = 70 indx = 71 indx = 72 indx = 73 indx = 74 indx = 75 indx = 76 indx = 77 indx = 78 indx = 79 indx = 80 indx = 81 indx = 82 indx = 83 indx = 84 indx = 85 indx = 86 indx = 87 indx = 88 indx = 89 indx = 90 indx = 91 indx = 92 indx = 93 indx = 94 indx = 95 indx = 96 indx = 97 indx = 98 indx = 99 indx = 100 indx = 101 indx = 102 indx = 103 indx = 104 indx = 105 indx = 106 indx = 107 indx = 108 indx = 109 indx = 110 indx = 111 indx = 112 indx = 113 indx = 114 indx = 115 indx = 116 indx = 117 indx = 118 indx = 119 indx = 120 indx = 121 indx = 122 indx = 123 indx = 124 indx = 125 indx = 126 indx = 127 indx = 128 indx = 129 indx = 130 indx = 131 indx = 132 indx = 133 indx = 134 indx = 135 indx = 136 indx = 137 indx = 138 indx = 139 indx = 140 indx = 141 indx = 142 indx = 143 indx = 144 indx = 145 indx = 146 indx = 147 indx = 148 indx = 149 indx = 150 indx = 151 indx = 152 indx = 153 indx = 154 indx = 155 indx = 156 indx = 157 indx = 158 indx = 159 indx = 160 indx = 161 indx = 162 indx = 163 indx = 164 indx = 165 indx = 166 indx = 167 indx = 168 indx = 169 indx = 170 indx = 171 indx = 172 indx = 173 indx = 174 indx = 175 indx = 176 indx = 177 indx = 178 indx = 179 indx = 180 indx = 181 indx = 182 indx = 183 indx = 184 indx = 185 indx = 186 indx = 187 indx = 188 indx = 189 indx = 190 indx = 191 indx = 192 indx = 193 indx = 194 indx = 195 indx = 196 indx = 197 indx = 198 indx = 199 indx = 200 indx = 201 indx = 202 indx = 203 indx = 204 indx = 205 indx = 206 indx = 207 indx = 208 indx = 209 indx = 210 indx = 211 indx = 212 indx = 213 indx = 214 indx = 215 indx = 216 indx = 217 indx = 218 indx = 219 indx = 220 indx = 221 indx = 222 indx = 223 indx = 224 indx = 225 indx = 226 indx = 227 indx = 228 indx = 229 indx = 230 indx = 231 indx = 232 indx = 233 indx = 234 indx = 235 indx = 236 indx = 237 indx = 238 indx = 239 indx = 240 indx = 241 indx = 242 indx = 243 indx = 244 indx = 245 indx = 246 indx = 247 indx = 248 indx = 249 indx = 250 indx = 251 indx = 252 indx = 253 indx = 254 indx = 255 indx = 256 indx = 257 indx = 258 indx = 259 indx = 260 indx = 261 indx = 262 indx = 263 indx = 264 indx = 265 indx = 266 indx = 267 indx = 268 indx = 269 indx = 270 indx = 271 indx = 272 indx = 273 indx = 274 indx = 275 indx = 276 indx = 277 indx = 278 indx = 279 indx = 280 indx = 281 indx = 282 indx = 283 indx = 284 indx = 285 indx = 286 indx = 287 indx = 288 indx = 289 indx = 290 indx = 291 indx = 292 indx = 293 indx = 294 indx = 295 indx = 296 indx = 297 indx = 298 indx = 299 indx = 300 indx = 301 indx = 302 indx = 303 indx = 304 indx = 305 indx = 306 indx = 307 indx = 308 indx = 309 indx = 310 indx = 311 indx = 312 indx = 313 indx = 314 indx = 315 indx = 316 indx = 317 indx = 318 indx = 319 indx = 320 indx = 321 indx = 322 indx = 323 indx = 324 indx = 325 indx = 326 indx = 327 indx = 328 indx = 329 indx = 330 indx = 331 indx = 332 indx = 333 indx = 334 indx = 335 indx = 336 indx = 337 indx = 338 indx = 339 indx = 340 indx = 341 indx = 342 indx = 343 indx = 344 indx = 345 indx = 346 indx = 347 indx = 348 indx = 349 indx = 350 indx = 351 indx = 352 indx = 353 indx = 354 indx = 355 indx = 356 indx = 357 indx = 358 indx = 359 indx = 360 indx = 361 indx = 362 indx = 363 indx = 364 indx = 365 indx = 366 indx = 367 indx = 368 indx = 369 indx = 370 indx = 371 indx = 372 indx = 373 indx = 374 indx = 375 indx = 376 indx = 377 indx = 378 indx = 379 indx = 380 indx = 381 indx = 382 indx = 383 indx = 384 indx = 385 indx = 386 indx = 387 indx = 388 indx = 389 indx = 390 indx = 391 indx = 392 indx = 393 indx = 394 indx = 395 indx = 396 indx = 397 indx = 398 indx = 399 indx = 400 indx = 401 indx = 402 indx = 403 indx = 404 indx = 405 indx = 406 indx = 407 indx = 408 indx = 409 indx = 410 indx = 411 indx = 412 indx = 413 indx = 414 indx = 415 indx = 416 indx = 417 indx = 418 indx = 419 indx = 420 indx = 421 indx = 422 indx = 423 indx = 424 indx = 425 indx = 426 indx = 427 indx = 428 indx = 429 indx = 430 indx = 431 indx = 432 indx = 433 indx = 434 indx = 435 indx = 436 indx = 437 indx = 438 indx = 439 indx = 440 indx = 441 indx = 442 indx = 443 indx = 444 indx = 445 indx = 446 indx = 447 indx = 448 indx = 449 indx = 450 indx = 451 indx = 452 indx = 453 indx = 454 indx = 455 indx = 456 indx = 457 indx = 458 indx = 459 indx = 460 indx = 461 indx = 462 indx = 463 indx = 464 indx = 465 indx = 466 indx = 467 indx = 468 indx = 469 indx = 470 indx = 471 indx = 472 indx = 473 indx = 474 indx = 475 indx = 476 indx = 477 indx = 478 indx = 479 indx = 480 indx = 481 indx = 482 indx = 483 indx = 484 indx = 485

6   Pass
n = randi(1000); a = tril(ones(n),-1); z_correct = 1:n; assert(isequal(lastzerorow(a),z_correct))

indx = 1 indx = 2 indx = 3 indx = 4 indx = 5 indx = 6 indx = 7 indx = 8 indx = 9 indx = 10 indx = 11 indx = 12 indx = 13 indx = 14 indx = 15 indx = 16 indx = 17 indx = 18 indx = 19 indx = 20 indx = 21 indx = 22 indx = 23 indx = 24 indx = 25 indx = 26 indx = 27 indx = 28 indx = 29 indx = 30 indx = 31 indx = 32 indx = 33 indx = 34 indx = 35 indx = 36 indx = 37 indx = 38 indx = 39 indx = 40 indx = 41 indx = 42 indx = 43 indx = 44 indx = 45 indx = 46 indx = 47 indx = 48 indx = 49 indx = 50 indx = 51 indx = 52 indx = 53 indx = 54 indx = 55 indx = 56 indx = 57 indx = 58 indx = 59 indx = 60 indx = 61 indx = 62 indx = 63 indx = 64 indx = 65 indx = 66 indx = 67 indx = 68 indx = 69 indx = 70 indx = 71 indx = 72 indx = 73 indx = 74 indx = 75 indx = 76 indx = 77 indx = 78 indx = 79 indx = 80 indx = 81 indx = 82 indx = 83 indx = 84 indx = 85 indx = 86 indx = 87 indx = 88 indx = 89 indx = 90 indx = 91 indx = 92 indx = 93 indx = 94 indx = 95 indx = 96 indx = 97 indx = 98 indx = 99 indx = 100 indx = 101 indx = 102 indx = 103 indx = 104 indx = 105 indx = 106 indx = 107 indx = 108 indx = 109 indx = 110 indx = 111 indx = 112 indx = 113 indx = 114 indx = 115 indx = 116 indx = 117 indx = 118 indx = 119 indx = 120 indx = 121 indx = 122 indx = 123 indx = 124 indx = 125 indx = 126 indx = 127 indx = 128 indx = 129 indx = 130 indx = 131 indx = 132 indx = 133 indx = 134 indx = 135 indx = 136 indx = 137 indx = 138 indx = 139 indx = 140 indx = 141 indx = 142 indx = 143 indx = 144 indx = 145 indx = 146 indx = 147 indx = 148 indx = 149 indx = 150 indx = 151 indx = 152 indx = 153 indx = 154 indx = 155 indx = 156 indx = 157 indx = 158 indx = 159 indx = 160 indx = 161 indx = 162 indx = 163 indx = 164 indx = 165 indx = 166 indx = 167 indx = 168 indx = 169 indx = 170 indx = 171 indx = 172 indx = 173 indx = 174 indx = 175 indx = 176 indx = 177 indx = 178 indx = 179 indx = 180 indx = 181 indx = 182 indx = 183 indx = 184 indx = 185 indx = 186 indx = 187 indx = 188

7   Pass
n = randi(1000); d = randi(n-1); a = tril(ones(n),-d); z_correct = min((0:n-1)+d,n); assert(isequal(lastzerorow(a),z_correct))

indx = 19 indx = 20 indx = 21 indx = 22 indx = 23 indx = 24 indx = 25 indx = 26 indx = 27 indx = 28 indx = 29 indx = 30 indx = 31 indx = 32 indx = 33 indx = 34 indx = 35 indx = 36 indx = 37 indx = 38 indx = 39 indx = 40 indx = 41 indx = 42 indx = 43 indx = 44 indx = 45 indx = 46 indx = 47 indx = 48 indx = 49 indx = 50 indx = 51 indx = 52 indx = 53 indx = 54 indx = 55 indx = 56 indx = 57 indx = 58 indx = 59 indx = 60 indx = 61 indx = 62 indx = 63 indx = 64 indx = 65 indx = 66 indx = 67 indx = 68 indx = 69 indx = 70 indx = 71 indx = 72 indx = 73 indx = 74 indx = 75 indx = 76 indx = 77 indx = 78 indx = 79 indx = 80 indx = 81 indx = 82 indx = 83 indx = 84 indx = 85 indx = 86 indx = 87 indx = 88 indx = 89 indx = 90 indx = 91 indx = 92 indx = 93 indx = 94 indx = 95 indx = 96 indx = 97 indx = 98 indx = 99 indx = 100 indx = 101 indx = 102 indx = 103 indx = 104 indx = 105 indx = 106 indx = 107 indx = 108 indx = 109 indx = 110 indx = 111 indx = 112 indx = 113 indx = 114 indx = 115 indx = 116 indx = 117 indx = 118 indx = 119 indx = 120 indx = 121 indx = 122 indx = 123 indx = 124 indx = 125 indx = 126 indx = 127 indx = 128 indx = 129 indx = 130 indx = 131 indx = 132 indx = 133 indx = 134 indx = 135 indx = 136 indx = 137 indx = 138 indx = 139 indx = 140 indx = 141 indx = 142 indx = 143 indx = 144 indx = 145 indx = 146 indx = 147 indx = 148 indx = 149 indx = 150 indx = 151 indx = 152 indx = 153 indx = 154 indx = 155 indx = 156 indx = 157 indx = 158 indx = 159 indx = 160 indx = 161 indx = 162 indx = 163 indx = 164 indx = 165 indx = 166 indx = 167 indx = 168 indx = 169 indx = 170 indx = 171 indx = 172 indx = 173 indx = 174 indx = 175 indx = 176 indx = 177 indx = 178 indx = 179 indx = 180 indx = 181 indx = 182 indx = 183 indx = 184 indx = 185 indx = 186 indx = 187 indx = 188 indx = 189 indx = 190 indx = 191 indx = 192 indx = 193 indx = 194 indx = 195 indx = 196 indx = 197 indx = 198 indx = 199 indx = 200 indx = 201 indx = 202 indx = 203 indx = 204 indx = 205 indx = 206 indx = 207 indx = 208 indx = 209 indx = 210 indx = 211 indx = 212 indx = 213 indx = 214 indx = 215 indx = 216 indx = 217 indx = 218 indx = 219 indx = 220 indx = 221 indx = 222 indx = 223 indx = 224 indx = 225 indx = 226 indx = 227 indx = 228 indx = 229 indx = 230 indx = 231 indx = 232 indx = 233 indx = 234 indx = 235 indx = 236 indx = 237 indx = 238 indx = 239 indx = 240 indx = 241 indx = 242 indx = 243 indx = 244 indx = 245 indx = 246 indx = 247 indx = 248 indx = 249 indx = 250 indx = 251 indx = 252 indx = 253 indx = 254 indx = 255 indx = 256 indx = 257 indx = 258 indx = 259 indx = 260 indx = 261 indx = 262 indx = 263 indx = 264 indx = 265 indx = 266 indx = 267 indx = 268 indx = 269 indx = 270 indx = 271 indx = 272 indx = 273 indx = 274 indx = 275 indx = 276 indx = 277 indx = 278 indx = 279 indx = 280 indx = 281 indx = 282 indx = 283 indx = 284 indx = 285 indx = 286 indx = 287 indx = 288 indx = 289 indx = 290 indx = 291 indx = 292 indx = 293 indx = 294 indx = 295 indx = 296 indx = 297 indx = 298 indx = 299 indx = 300 indx = 301 indx = 302 indx = 303 indx = 304 indx = 305 indx = 306 indx = 307 indx = 308 indx = 309 indx = 310 indx = 311 indx = 312 indx = 313 indx = 314 indx = 315 indx = 316 indx = 317 indx = 318 indx = 319 indx = 320 indx = 321 indx = 322 indx = 323 indx = 324 indx = 325 indx = 326 indx = 327 indx = 328 indx = 329 indx = 330 indx = 331 indx = 332 indx = 333 indx = 334 indx = 335 indx = 336 indx = 337 indx = 338 indx = 339 indx = 340 indx = 341 indx = 342 indx = 343 indx = 344 indx = 345 indx = 346 indx = 347 indx = 348 indx = 349 indx = 350 indx = 351 indx = 352 indx = 353 indx = 354 indx = 355 indx = 356 indx = 357 indx = 358 indx = 359 indx = 360 indx = 361 indx = 362 indx = 363 indx = 364 indx = 365 indx = 366 indx = 367 indx = 368 indx = 369 indx = 370 indx = 371 indx = 372 indx = 373 indx = 374 indx = 375 indx = 376 indx = 377 indx = 378 indx = 379 indx = 380 indx = 381 indx = 382 indx = 383 indx = 384 indx = 385 indx = 386 indx = 387 indx = 388 indx = 389 indx = 390 indx = 391 indx = 392 indx = 393 indx = 394 indx = 395 indx = 396 indx = 397 indx = 398 indx = 399 indx = 400 indx = 401 indx = 402 indx = 403 indx = 404 indx = 405 indx = 406 indx = 407 indx = 408 indx = 409 indx = 410 indx = 411 indx = 412 indx = 413 indx = 414 indx = 415 indx = 416 indx = 417 indx = 418 indx = 419 indx = 420 indx = 421 indx = 422 indx = 423 indx = 424 indx = 425 indx = 426 indx = 427 indx = 428 indx = 429 indx = 430 indx = 431 indx = 432 indx = 433 indx = 434 indx = 435 indx = 436 indx = 437 indx = 438 indx = 439 indx = 440 indx = 441 indx = 442 indx = 443 indx = 444 indx = 445 indx = 446 indx = 447 indx = 448 indx = 449 indx = 450 indx = 451 indx = 452 indx = 453 indx = 454 indx = 455 indx = 456 indx = 457 indx = 458 indx = 459 indx = 460 indx = 461 indx = 462 indx = 463 indx = 464 indx = 465 indx = 466 indx = 467 indx = 468 indx = 469 indx = 470 indx = 471 indx = 472 indx = 473 indx = 474 indx = 475 indx = 476 indx = 477 indx = 478 indx = 479 indx = 480 indx = 481 indx = 482 indx = 483 indx = 484 indx = 485 indx = 486 indx = 487 indx = 488 indx = 489 indx = 490 indx = 491 indx = 492 indx = 493 indx = 494 indx = 495 indx = 496 indx = 497 indx = 498 indx = 499 indx = 500 indx = 501 indx = 502 indx = 503 indx = 504 indx = 505 indx = 506 indx = 507 indx = 508 indx = 509 indx = 510 indx = 511 indx = 512 indx = 513 indx = 514 indx = 515 indx = 516 indx = 517 indx = 518 indx = 519 indx = 520 indx = 521 indx = 522 indx = 523 indx = 524 indx = 525 indx = 526 indx = 527 indx = 528 indx = 529 indx = 530 indx = 531 indx = 532 indx = 533 indx = 534 indx = 535 indx = 536 indx = 537 indx = 538 indx = 539 indx = 540 indx = 541 indx = 542 indx = 543 indx = 544 indx = 545 indx = 546 indx = 547 indx = 548 indx = 549 indx = 550 indx = 551 indx = 552 indx = 553 indx = 554 indx = 555 indx = 556 indx = 557 indx = 558 indx = 559 indx = 560 indx = 561 indx = 562 indx = 563 indx = 564 indx = 565 indx = 566 indx = 567 indx = 568 indx = 569 indx = 570 indx = 571 indx = 572 indx = 573 indx = 574 indx = 575 indx = 576 indx = 577 indx = 578 indx = 579 indx = 580 indx = 581 indx = 582 indx = 583 indx = 584 indx = 585 indx = 586 indx = 587 indx = 588 indx = 589 indx = 590 indx = 591 indx = 592 indx = 593 indx = 594 indx = 595 indx = 596 indx = 597 indx = 598 indx = 599 indx = 600 indx = 601 indx = 602 indx = 603 indx = 604 indx = 605 indx = 606 indx...

8   Pass
a = magic(10)-1; z_correct = [0 0 1 0 0 0 0 0 0 0]; assert(isequal(lastzerorow(a),z_correct))

indx = 0×1 empty double column vector indx = 0×1 empty double column vector indx = 1 indx = 0×1 empty double column vector indx = 0×1 empty double column vector indx = 0×1 empty double column vector indx = 0×1 empty double column vector indx = 0×1 empty double column vector indx = 0×1 empty double column vector indx = 0×1 empty double column vector

9   Pass
a = [0 0 9 0; 0 0 1 8; 0 0 4 0; 0 0 2 3; 0 6 7 5]; z_correct = [5 4 0 3]; assert(isequal(lastzerorow(a),z_correct))

indx = 5 indx = 4 indx = 0×1 empty double column vector indx = 3

10   Pass
a = [0 0 0 0 -4 0 0 0 0; 0 0 0 -3 -3 -3 0 0 0; 0 0 -2 3 -2 2 2 0 0; 0 -1 2 -1 1 -1 -1 1 0]; z_correct = [4 3 2 1 0 1 2 3 4]; assert(isequal(lastzerorow(a),z_correct))

indx = 4 indx = 3 indx = 2 indx = 1 indx = 0×1 empty double column vector indx = 1 indx = 2 indx = 3 indx = 4

Suggested Problems

More from this Author44

Community Treasure Hunt

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

Start Hunting!