From: David B. <Dav...@mo...> - 2005-12-08 16:19:35
|
William Poetra Yoga Hadisoeseno wrote: >On 12/8/05, David Bateman <Dav...@mo...> wrote: > > >>It just does a cat along the last dimension of the cell array so that >>for example >> >>c = {[1], [2 3 4]; [5; 9], [6 7 8; 10 11 12]}; >> >>becomes >> >>c1 = {[1, 2, 3, 4] ; [5 6 7 8; 9 10 11 12]} >> >>after the first interation. For 2-D there is only one iteration of the >>loop and the last cat operation is handled by "m = cat (1, c1{:})". >> >> >> > >OK, thanks :) > > > >>The fact is I'm not sure what you are trying to achieve with your >>changes. What was wrong with the previous implementation? cell2mat.m >>itself needs no argument dimension checking, as if the arguments are >>wrong, the dimension checking in the "cat" operation will cause an error >>and exit from cell2mat. For example with the current version of cell2mat >>I get the following, when passing it matrices that can't be concatenated. >> >>octave:2> C = {[1], [2 3 4]; [5; 9; 13], [6 7 8; 10 11 12]}; >>octave:3> cell2mat(C) >>error: cat: dimension mismatch >>error: evaluating assignment expression near line 65, column 14 >>error: evaluating for command near line 64, column 5 >>error: evaluating for command near line 60, column 3 >>error: called from `cell2mat' in file >>`/opt/octave-2.9/share/octave/2.9.4/site/m/octave-forge/cell/cell2mat.m' >> >> >> > >Yes, but I wanted to make sure cell2mat.m checks for every restriction >specified in the Matlab documentation (same data type, can concatenate >into a hyperrectangle, matching dimensions for neighbouring cells). >Instead of letting cat print out the error, I think we should let >cell2mat do it. For example: > >octave:21> C = {[1], [2 3 4]; [5; 9; 13], [6 7 8; 10 11 12]}; >octave:22> cell2mat(C) >error: cell2mat: the contents of c must be able to concatenate into a >hyperrectangle >error: evaluating if command near line 75, column 13 >error: evaluating if command near line 72, column 11 >error: evaluating for command near line 69, column 9 >error: evaluating if command near line 67, column 7 >error: evaluating for command near line 66, column 5 >error: evaluating if command near line 54, column 3 >error: called from `cell2mat' in file `/home/william/cell2mat.m' > >Admittedly the checking part is inefficient and ugly, so I'm asking >for some help here ;) > > > Again, why? Here is matlab's output >> C = {[1], [2, 3, 4; 6 7 8]; [5; 9],[10 11 12]} >> cell2mat(C) ??? Error using ==> cat CAT arguments dimensions are not consistent. Error in ==> cell2mat at 92 m{n} = cat(2,c{n,:}); The error message seems to indicate that matlab just lets cat generate the error as well. >>Note that although >> >>C = {[1, 2], [3, 4]; [5; 9],[6 7 8; 10 11 12]}; >>cell2mat(C) >> >> >> > >This one works in the old cell2mat, but not in the new cell2mat. Do >you think it should (work)? I mean, by the Matlab documentation, [1, >2] and [5; 9] are neighbours, but they differ in size (1x2 and 2x1, >while the neighbouring dimension is 1, thus while we ignore the first >dimension, we are comparing 2 to 1). How does Matlab behave? > > > Matlab doesn't respect their own documentation either >> C = {[1, 2], [3, 4]; [5; 9],[6 7 8; 10 11 12]}; >> cell2mat(C) ans = 1 2 3 4 5 6 7 8 9 10 11 12 This is with R14sp2.. >>works, the generalization >> >>C = {[1], [2, 3, 4; 6 7 8]; [5; 9],[10 11 12]} >>cell2mat(C) >> >>doesn't, even though conceptually the meaning is clear in terms of the >>hyper-rectangle. In general there must be a grid in the >>hyper-rectangular along which all matrices fill the elements of this >>grid. Matlab has the same behaviour. >> >> >> > >I didn't realize the importance of the sentence "for each pair of >neighboring cells, the dimensions of the cells' contents must match, >excluding the dimension in which the cells are neighbors" until I read >your mail. I've added this item in the documentation (new file is >attached). Yes, your view of a "grid" is consistent with the Matlab >documentation. > >By the way, I haven't implemented the "same data type" restriction. >Should cell2mat work that way? I mean, intuitively, concatenating >logical arrays with double arrays should at least work. How does >Matlab behave? Matlab's documentation itself says that c must have >contents of the same data type. > > > >> C = {[1;2],ones(2,2)==1} C = [2x1 double] [2x2 logical] >> cell2mat(C) ??? Error using ==> cell2mat All contents of the input cell array must be of the same data type. However, this seems stupid to me, as logical arrays are supposed to be promoted to double in normal usage... I'd prefer that the above remained legal.. Regards David -- David Bateman Dav...@mo... Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary |