From octave-maintainers-request at bevo dot che dot wisc dot edu Wed May 15 09:51:32 2002 Subject: Re: cell arrays and structure arrays From: Paul Kienzle To: "John W. Eaton" , octave-maintainers mailing list Date: Wed, 15 May 2002 10:50:43 -0400 > * The [ ] operator needs to be fixed so that it can be used to > concatentate cell arrays as well as numeric and character arrays. There is something to be said for moving concatenation into the operator table rather than hard coding it into tree_matrix. Then it would be natural to construct block sparse matrices and symbolic matrices. The following comment comes from symbolic.html: Limitations/Features Currently there is no support for symbolic matrices. I think it would require a few changes to the parser to do it nicely: for example: sym_matrix = [x+1, x+5; x^2+4,x^2+2*x+1]; I could make a function like sym_matrix(the_rows,the_columns,x+1, ... ) that returned a symbolic matrix but this would be a bit of a kludge. Indeed, matlab provides horzcat and vertcat methods for objects. It would be nice to be able to precalculate the size and type of the resulting matrix before starting any concatenation so that you are not resizing the matrix every step of the way. You won't be able to do that with just horzcat and vertcat. Instead you need some way to precalculate the resulting type and dimension, build a new matrix of that type, and insert appropriate octave values into the indices of that matrix. Then you could write tree_matrix as follows: precalculate r = 0 for each horizontal cat in vertical cat c = 0 rows = firstvalue->rows() type = firstvalue->type() for each octave value in horizontal cat horztype = cancat(horztype, value->type()) if rows != value->rows() error c += value->columns(); end if first verttype = horztype cols = c else verttype = cancat(verttype,horztype) if cols != c error end r += rows; end construct octave_value ret(type,r,c); r = 0 for each horizontal cat in vertical cat c = 0 rows = firstvalue->rows(); for each octave value in horizontal cat ret->insert(r,c,value); c += value->columns(); end r += rows; end With automatic type conversion, my code will do something different than a series of horzcat/vertcat calls. Consider the following: [ 1, 2, { 3, 4} ] With horzcat, this is horzcat(horzcat(1,2), { 3, 4 } ) which would be { [1, 2], 3, 4 } But as I've written it, this will be { 1, 2, 3, 4 } Maybe that's why matlab says: >> [ 1, 2, { 3, 4} ] ??? Error using ==> horzcat Conversion to cell from double is not possible. - Paul