From bug-octave-request at bevo dot che dot wisc dot edu Fri Nov 6 14:01:44 1998 Subject: Re: more 2.1.8 problems From: "John W. Eaton" To: Joao Cardoso Cc: bug-octave at bevo dot che dot wisc dot edu Date: Fri, 6 Nov 1998 14:01:17 -0600 (CST) On 6-Nov-1998, Joao Cardoso wrote: | John W. Eaton wrote: | > | > On 6-Nov-1998, Joao Cardoso wrote: | > | > | Also, I don't know how to use the new `for i=string', | ... | > Try | > | > for i = ["foo"; "bar"], i, endfor | > | > It works on the columns of a character matrix, for compatibility with | > Matlab. | | nop, | | LOADPATH = ~/octave//:: | octave-2.1.8:1> for i = ["foo"; "bar"], i, endfor | error: invalid type in for loop expression near line 1, column 1 Ah. OK, here is a patch to try. Thanks, jwe Fri Nov 6 12:14:29 1998 John W. Eaton * pt-loop.cc (tree_for_command::eval): Move code for string RHS outside if clause for matrix types. Index: pt-loop.cc =================================================================== RCS file: /home/jwe/src/master/octave/src/pt-loop.cc,v retrieving revision 1.4 diff -c -r1.4 pt-loop.cc *** pt-loop.cc 1998/10/16 18:05:31 1.4 --- pt-loop.cc 1998/11/06 19:58:41 *************** *** 215,236 **** do_for_loop_once (ult, rhs, quit); } else if (rhs.is_matrix_type ()) { - charMatrix chm_tmp; Matrix m_tmp; ComplexMatrix cm_tmp; int nr; int steps; ! if (rhs.is_string ()) ! { ! chm_tmp = rhs.char_matrix_value (); ! nr = chm_tmp.rows (); ! steps = chm_tmp.columns (); ! } ! else if (rhs.is_real_matrix ()) { m_tmp = rhs.matrix_value (); nr = m_tmp.rows (); --- 215,255 ---- do_for_loop_once (ult, rhs, quit); } + else if (rhs.is_string ()) + { + charMatrix chm_tmp = rhs.char_matrix_value (); + int nr = chm_tmp.rows (); + int steps = chm_tmp.columns (); + + if (error_state) + return; + + if (nr == 1) + DO_LOOP (chm_tmp (0, i)); + else + { + for (int i = 0; i < steps; i++) + { + octave_value val (chm_tmp.extract (0, i, nr-1, i), true); + + bool quit = false; + + do_for_loop_once (ult, val, quit); + + if (quit) + break; + } + } + } else if (rhs.is_matrix_type ()) { Matrix m_tmp; ComplexMatrix cm_tmp; int nr; int steps; ! if (rhs.is_real_matrix ()) { m_tmp = rhs.matrix_value (); nr = m_tmp.rows (); *************** *** 246,271 **** if (error_state) return; ! if (rhs.is_string ()) ! { ! if (nr == 1) ! DO_LOOP (chm_tmp (0, i)); ! else ! { ! for (int i = 0; i < steps; i++) ! { ! octave_value val (chm_tmp.extract (0, i, nr-1, i), true); ! ! bool quit = false; ! ! do_for_loop_once (ult, val, quit); ! ! if (quit) ! break; ! } ! } ! } ! else if (rhs.is_real_matrix ()) { if (nr == 1) DO_LOOP (m_tmp (0, i)); --- 265,271 ---- if (error_state) return; ! if (rhs.is_real_matrix ()) { if (nr == 1) DO_LOOP (m_tmp (0, i));