Mercurial > hg > octave-lyh
comparison liboctave/dMatrix.cc @ 10805:8c858a1a2079
simplify Matrix::extract
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 20 Jul 2010 12:56:05 +0200 |
parents | 832732c2eb80 |
children | 7c542263a92a |
comparison
equal
deleted
inserted
replaced
10804:3d5c6b84ddaf | 10805:8c858a1a2079 |
---|---|
578 Matrix::extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const | 578 Matrix::extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const |
579 { | 579 { |
580 if (r1 > r2) { octave_idx_type tmp = r1; r1 = r2; r2 = tmp; } | 580 if (r1 > r2) { octave_idx_type tmp = r1; r1 = r2; r2 = tmp; } |
581 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; } | 581 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; } |
582 | 582 |
583 octave_idx_type new_r = r2 - r1 + 1; | 583 return index (idx_vector (r1, r2+1), idx_vector (c1, c2+1)); |
584 octave_idx_type new_c = c2 - c1 + 1; | |
585 | |
586 Matrix result (new_r, new_c); | |
587 | |
588 for (octave_idx_type j = 0; j < new_c; j++) | |
589 for (octave_idx_type i = 0; i < new_r; i++) | |
590 result.xelem (i, j) = elem (r1+i, c1+j); | |
591 | |
592 return result; | |
593 } | 584 } |
594 | 585 |
595 Matrix | 586 Matrix |
596 Matrix::extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const | 587 Matrix::extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const |
597 { | 588 { |
598 Matrix result (nr, nc); | 589 return index (idx_vector (r1, r1 + nr), idx_vector (r2, r2 + nr)); |
599 | |
600 for (octave_idx_type j = 0; j < nc; j++) | |
601 for (octave_idx_type i = 0; i < nr; i++) | |
602 result.xelem (i, j) = elem (r1+i, c1+j); | |
603 | |
604 return result; | |
605 } | 590 } |
606 | 591 |
607 // extract row or column i. | 592 // extract row or column i. |
608 | 593 |
609 RowVector | 594 RowVector |